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에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.