OPEN-SOURCE SCRIPT
Zaktualizowano 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.
Informacje o Wersji
With the input.color function, the option to adjust the line colours individually via the settings has been added to the script.Instead of writing down the colour directly in the line.new function, keywords are created which contain the input function. These keywords are then stored in line.new(colour = xxx).
Further explanation of the use of the indicator:
Explanation of the zones and terminology:
Value Area (VA) = 70% of all trading on this day took place in this zone. The value is adjustable. By de-fault, however, the profile is considered with the value 70%.
Point of Control (POC) = Area of the most traded price of the trading day (red)
Value Area High (VAH) = High of the VA (blue)
Value Area Low (VAL) = Low of the VA (blue)
Initial Balance (IB) = Corresponds to the high and low of the first trading hour of the day.
Initial Balance High (IBH) = High of the opening range of the trading day (orange)
Initial Balance Low (IBL) = Low of the opening range of the trading day (orange)
Note that this indicator always shows the previous day's zones and not those of the current day as these may not yet be closed.
Recognising trend following and reversal:
In this example you can see how the profile can be read over several days.
We see at the beginning how the Poc and also the VA continue to move upwards while the price always moves above the POC (Point of Control = most traded area of the day). The market is in a clear uptrend. In the circles drawn you can see how the previous day's VA repeatedly serves as support. The price also opens above the POC and near or above the VAH. At the end of the movement you can see how the previous day's POC is broken, followed by a consolidation phase with an initial downtrend. In this ex-treme case, every untested previous day's POC is worked off by the uptrend. Untested POCs can be used as targets. In the consolidation phase, it is also nice to observe how the POC starts to move down-wards, just as the VA starts to move downwards.
Balance days:
In this example, you can see how the previous day's profile lies completely within the previous day's pro-file. There is a balance here. The price has gone through a sideways phase for a total of 2 days, where-by the VAL is repeatedly rejected and a strong breakout from this zone occurs. Note how the last un-tested POC is then approached.
Another example of a balance day including the initial balance (first trading hour of the day). We see here that at the beginning the day opened far outside the VA. Accordingly, we can deduce that we had a strong sell-off. The next profile is again completely within the previous day's profile. However, unlike the previous example, the context shows us that the consolidation took place after an initial sell-off. The breakout is not complete and the price falls back into the balance area on the following day. This is a signal that the downward movement will continue.
The profile generally shows you the history of the market. It is important to understand the TPO in order to read it correctly. The TPO is not an indicator in the classical sense, but an organisational tool that shows you data in an organised way. This indicator only helps you to display key levels of the last com-pleted profile on the current day.
Keep statistics to derive correlations between the current day's opening in relation to the previous day's opening and the VA. Observe the shift of the POC in relation to the price. The indicator gives you a pic-ture of what market participants traded the day before. In the following example you can see how it could be recognised that the market continues to move sideways in the longer term or whether you should ra-ther look for short or long positions intraday.
The first hour of trading in the 15m timeframe opens within the wide opening range of the previous day. The price falls back into the VA and tests the initial balance low in the course of the day and even goes as far as the POC but does not leave the IB range until the end of the day. You can then see that the previous day's profile encloses the previous day's VAH profile. The previous day's IB is completely within the previous day's IB. The price continues to trade sideways. Note the reactions at the important levels. Since you can assume that it is a balance day (sideways market) you could enter scalps at the important zones.
I hope this helps you to understand the indicator better. Be sure to familiarise yourself with the TPO pro-file. This indicator only shows you an application of the original TPO by reading the previous day's zones and opening zones. The original provides much more information such as a view of the bell curve or real time evolution of the market.
Informacje o Wersji
New Chart ScreenSkrypt open-source
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Wyłączenie odpowiedzialności
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Skrypt open-source
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Wyłączenie odpowiedzialności
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.