OPEN-SOURCE SCRIPT
Previous TPO

Indicator Summary
This Pine Script indicator, "Previous TPO," is designed to calculate and display five key price levels from the previous trading day's market activity. It uses a 30-minute TPO (Time Price Opportunity) profile, which is a method of organizing price by time to find areas of high and low activity.
The five levels it plots on the current day are:
1. Previous Value Area High (VAH)
2. Previous Value Area Low (VAL)
3. Previous Point of Control (POC)
4. Previous Initial Balance High (IBH)
5. Previous Initial Balance Low (IBL)
The script is built to be efficient, running its main calculation only once at the beginning of each new day. It also includes an automatic line management system to delete old lines, preventing the "Too many lines" error and keeping the chart clean.
How the Code Works
1. Data Collection: At the start of a new day (00:00), the script looks back at the chart's history. It uses request.security to access 30-minute bar data.
2. Collector Loop: It then loops backward, bar by bar, to find and store 48 unique 30-minute High/Low data points, which represents the full 24-hour range of the previous day.
3. TPO Profile: With this 30-minute data, it builds a TPO profile. It divides the previous day's price range into small bins (price levels) and counts how many 30-minute periods "touched" each price bin.
4. Level Calculation:
o POC: It finds the price bin with the highest TPO count (the most traded price) and sets it as the Point of Control.
o VAH/VAL: It starts at the POC and expands outward, adding the next-most-traded price bins until 70% (or the user-defined percentage) of the day's TPOs are included. The highest and lowest prices of this range are the Value Area High and Value Area Low.
o IBH/IBL: It identifies the high and low of the first hour (the first two 30-minute bars) of the previous day to set the Initial Balance High and Initial Balance Low.
5. Drawing: The script draws these five levels as horizontal lines across the current trading day, providing a constant reference.
6. Line Management: It keeps track of all lines in an array. When the total number of lines exceeds the user's limit (e.g., 50 days * 5 lines = 250), it automatically deletes the oldest lines from the chart.
Usefulness for Trading
This indicator provides a powerful framework for intraday traders by contextualizing the current day's price action against the previous day's "auction."
• Key Support/Resistance: The VAH, VAL, and POC act as significant support and resistance lev-els. Price reacting at these levels can signal mean reversion, while acceptance beyond them can signal a trend or expansion day.
• Value Area as Context: Trading inside the previous day's value area (between VAH and VAL) is often seen as "balanced" or "range-bound" trading. Trading outside of it is "unbalanced" or "trending."
• POC as a "Magnet": The POC, being the area of highest volume/time, often acts as a "magnet" or "center of gravity" for price.
• Opening Range: The Initial Balance (IB) levels show the opening range. A breakout from this range is often a key signal for the day's initial direction.
• 80% Rule: The script contains (currently commented-out) setup logic for the "80% Rule." This is a specific Market Profile strategy where:
1. The market opens inside the previous day's Value Area.
2. The Initial Balance fails to extend outside the VA (e.g., in a short setup, the IB high stays below the VAH).
3. This setup suggests an 80% probability that the price will rotate and test the other side of the Value Area (e.g., test the VAL).
Publication and restrictions
This script is published under the Mozilla Public Licence 2.0 (MPL 2.0) and is therefore suitable for publi-cation as an open source indicator on TradingView.
Timeframe limitation: The indicator is designed for intraday timeframes. Timeframes below 10 minutes do not work and lead to an error. Recommended time frame 30 minutes.
It will not work correctly on:
Time frame under 10 minutes: The data collection loop (max_bars_to_check = 3000) is not large enough to collect the bars required for a full day on a 5-minute chart or smaller.
High time frames (e.g. 1H, 4H, Daily): The script's logic is based on a chart timeframe 30-minute data that it requests. If higher time frames are selected, the script works but the zones are no longer correct or become irrelevant.
This Pine Script indicator, "Previous TPO," is designed to calculate and display five key price levels from the previous trading day's market activity. It uses a 30-minute TPO (Time Price Opportunity) profile, which is a method of organizing price by time to find areas of high and low activity.
The five levels it plots on the current day are:
1. Previous Value Area High (VAH)
2. Previous Value Area Low (VAL)
3. Previous Point of Control (POC)
4. Previous Initial Balance High (IBH)
5. Previous Initial Balance Low (IBL)
The script is built to be efficient, running its main calculation only once at the beginning of each new day. It also includes an automatic line management system to delete old lines, preventing the "Too many lines" error and keeping the chart clean.
How the Code Works
1. Data Collection: At the start of a new day (00:00), the script looks back at the chart's history. It uses request.security to access 30-minute bar data.
2. Collector Loop: It then loops backward, bar by bar, to find and store 48 unique 30-minute High/Low data points, which represents the full 24-hour range of the previous day.
3. TPO Profile: With this 30-minute data, it builds a TPO profile. It divides the previous day's price range into small bins (price levels) and counts how many 30-minute periods "touched" each price bin.
4. Level Calculation:
o POC: It finds the price bin with the highest TPO count (the most traded price) and sets it as the Point of Control.
o VAH/VAL: It starts at the POC and expands outward, adding the next-most-traded price bins until 70% (or the user-defined percentage) of the day's TPOs are included. The highest and lowest prices of this range are the Value Area High and Value Area Low.
o IBH/IBL: It identifies the high and low of the first hour (the first two 30-minute bars) of the previous day to set the Initial Balance High and Initial Balance Low.
5. Drawing: The script draws these five levels as horizontal lines across the current trading day, providing a constant reference.
6. Line Management: It keeps track of all lines in an array. When the total number of lines exceeds the user's limit (e.g., 50 days * 5 lines = 250), it automatically deletes the oldest lines from the chart.
Usefulness for Trading
This indicator provides a powerful framework for intraday traders by contextualizing the current day's price action against the previous day's "auction."
• Key Support/Resistance: The VAH, VAL, and POC act as significant support and resistance lev-els. Price reacting at these levels can signal mean reversion, while acceptance beyond them can signal a trend or expansion day.
• Value Area as Context: Trading inside the previous day's value area (between VAH and VAL) is often seen as "balanced" or "range-bound" trading. Trading outside of it is "unbalanced" or "trending."
• POC as a "Magnet": The POC, being the area of highest volume/time, often acts as a "magnet" or "center of gravity" for price.
• Opening Range: The Initial Balance (IB) levels show the opening range. A breakout from this range is often a key signal for the day's initial direction.
• 80% Rule: The script contains (currently commented-out) setup logic for the "80% Rule." This is a specific Market Profile strategy where:
1. The market opens inside the previous day's Value Area.
2. The Initial Balance fails to extend outside the VA (e.g., in a short setup, the IB high stays below the VAH).
3. This setup suggests an 80% probability that the price will rotate and test the other side of the Value Area (e.g., test the VAL).
Publication and restrictions
This script is published under the Mozilla Public Licence 2.0 (MPL 2.0) and is therefore suitable for publi-cation as an open source indicator on TradingView.
Timeframe limitation: The indicator is designed for intraday timeframes. Timeframes below 10 minutes do not work and lead to an error. Recommended time frame 30 minutes.
It will not work correctly on:
Time frame under 10 minutes: The data collection loop (max_bars_to_check = 3000) is not large enough to collect the bars required for a full day on a 5-minute chart or smaller.
High time frames (e.g. 1H, 4H, Daily): The script's logic is based on a chart timeframe 30-minute data that it requests. If higher time frames are selected, the script works but the zones are no longer correct or become irrelevant.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。