OPEN-SOURCE SCRIPT
PER Bands (Auto EPS)

PER Bands Indicator - Technical Specification
Function
This PineScript v6 overlay indicator displays horizontal price bands based on Price-to-Earnings Ratio multiples. The indicator calculates price levels by multiplying earnings per share values by user-defined PER multiples, then plots these levels as horizontal lines on the chart.
Data Sources
The script attempts to automatically retrieve earnings per share data using TradingView's `request.financial()` function. The system first queries trailing twelve months EPS data, then annual EPS data if TTM is unavailable. When automatic retrieval fails or returns zero values, the indicator uses manually entered EPS values as a fallback.
Configuration Options
Users can configure five separate PER multiples (default values: 10x, 15x, 20x, 25x, 30x). Each band supports individual color customization and adjustable line width settings from 1 to 5 pixels. The indicator includes toggles for band visibility and optional fill areas between adjacent bands with 95% transparency.
Visual Components
The indicator plots five horizontal lines representing different PER valuation levels. Optional fill areas create colored zones between consecutive bands. A data table in the top-right corner displays current EPS source, EPS value, current PER ratio, and calculated price levels for each configured multiple.
Calculation Method
The indicator performs the following calculations:
- Band Price = Current EPS × PER Multiple
- Current PER = Current Price ÷ Current EPS
These calculations update on each bar close using the most recent available EPS data.
Alert System
The script includes alert conditions for price crossovers above the lowest PER band and crossunders below the highest PER band. Additional alert conditions can be configured for any band level through the alert creation interface.
Debug Features
Debug mode displays character markers on the chart indicating when TTM or annual EPS data is available. This feature helps users verify which data source the indicator is using for calculations.
Data Requirements
The indicator requires positive, non-zero EPS values to function correctly. Stocks with negative earnings or zero EPS will display "N/A" for current PER calculations, though bands will still plot using the manual EPS input value.
Exchange Compatibility
Automatic EPS data availability varies by exchange. United States equity markets typically provide comprehensive fundamental data coverage. International markets may have limited automatic data availability, requiring manual EPS input for accurate calculations.
Technical Limitations
The indicator cannot fetch real-time EPS updates and relies on TradingView's fundamental data refresh schedule. Historical EPS changes are not reflected in past band positions, as the indicator uses current EPS values for all historical calculations.
Display Settings
The information table shows EPS source type (TTM Auto, Annual Auto, Manual, or Manual Fallback), allowing users to verify data accuracy. The table refreshes only on the last bar to optimize performance and reduce computational overhead.
Code Structure
Built using PineScript v6 syntax with proper scope management for plot and fill functions. The script uses global scope for all plot declarations and conditional logic within plot parameters to handle visibility settings.
Version Requirements
This indicator requires TradingView Pine Script version 6 or later due to the use of `request.financial()` functions and updated syntax requirements for plot titles and fill operations.
Function
This PineScript v6 overlay indicator displays horizontal price bands based on Price-to-Earnings Ratio multiples. The indicator calculates price levels by multiplying earnings per share values by user-defined PER multiples, then plots these levels as horizontal lines on the chart.
Data Sources
The script attempts to automatically retrieve earnings per share data using TradingView's `request.financial()` function. The system first queries trailing twelve months EPS data, then annual EPS data if TTM is unavailable. When automatic retrieval fails or returns zero values, the indicator uses manually entered EPS values as a fallback.
Configuration Options
Users can configure five separate PER multiples (default values: 10x, 15x, 20x, 25x, 30x). Each band supports individual color customization and adjustable line width settings from 1 to 5 pixels. The indicator includes toggles for band visibility and optional fill areas between adjacent bands with 95% transparency.
Visual Components
The indicator plots five horizontal lines representing different PER valuation levels. Optional fill areas create colored zones between consecutive bands. A data table in the top-right corner displays current EPS source, EPS value, current PER ratio, and calculated price levels for each configured multiple.
Calculation Method
The indicator performs the following calculations:
- Band Price = Current EPS × PER Multiple
- Current PER = Current Price ÷ Current EPS
These calculations update on each bar close using the most recent available EPS data.
Alert System
The script includes alert conditions for price crossovers above the lowest PER band and crossunders below the highest PER band. Additional alert conditions can be configured for any band level through the alert creation interface.
Debug Features
Debug mode displays character markers on the chart indicating when TTM or annual EPS data is available. This feature helps users verify which data source the indicator is using for calculations.
Data Requirements
The indicator requires positive, non-zero EPS values to function correctly. Stocks with negative earnings or zero EPS will display "N/A" for current PER calculations, though bands will still plot using the manual EPS input value.
Exchange Compatibility
Automatic EPS data availability varies by exchange. United States equity markets typically provide comprehensive fundamental data coverage. International markets may have limited automatic data availability, requiring manual EPS input for accurate calculations.
Technical Limitations
The indicator cannot fetch real-time EPS updates and relies on TradingView's fundamental data refresh schedule. Historical EPS changes are not reflected in past band positions, as the indicator uses current EPS values for all historical calculations.
Display Settings
The information table shows EPS source type (TTM Auto, Annual Auto, Manual, or Manual Fallback), allowing users to verify data accuracy. The table refreshes only on the last bar to optimize performance and reduce computational overhead.
Code Structure
Built using PineScript v6 syntax with proper scope management for plot and fill functions. The script uses global scope for all plot declarations and conditional logic within plot parameters to handle visibility settings.
Version Requirements
This indicator requires TradingView Pine Script version 6 or later due to the use of `request.financial()` functions and updated syntax requirements for plot titles and fill operations.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。