OPEN-SOURCE SCRIPT
Multi-Timeframe Bollinger Bands

My hope is to optimize the settings for this indicator and reintroduce it as a "strategy" with suggested position entry and exit points shown in the price pane.
I’ve been having good results setting the “Bollinger Band MA Length” in the Input tab to between 5 and 10. You can use the standard 20 period, but your results will not be as granular.
This indicator has proven very good at finding local tops and bottoms by combining data from multiple timeframes. Use timeframes that are lower than the timeframe you are viewing in your price pane. Be cognizant that the indicator, like other oscillators, does occasionally produce divergences at tops and bottoms.
Any feedback is appreciated.
Overview
This indicator is an oscillator that measures the normalized position of the price relative to Bollinger Bands across multiple timeframes. It takes the price's position within the Bollinger Bands (calculated on different timeframes) and averages those positions to create a single value that oscillates between 0 and 1. This value is then plotted as the oscillator, with reference lines and colored regions to help interpret the price's relative strength or weakness.
How It Works
Bollinger Band Calculation:
The indicator uses a custom function f_getBBPosition() to calculate the position of the price within Bollinger Bands for a given timeframe.
Price Position Normalization:
For each timeframe, the function normalizes the price's position between the upper and lower Bollinger Bands.
It calculates three positions based on the high, low, and close prices of the requested timeframe:
pos_high = (High - Lower Band) / (Upper Band - Lower Band)
pos_low = (Low - Lower Band) / (Upper Band - Lower Band)
pos_close = (Close - Lower Band) / (Upper Band - Lower Band)
If the upper band is not greater than the lower band or if the data is invalid (e.g., na), it defaults to 0.5 (the midline).
The average of these three positions (avg_pos) represents the normalized position for that timeframe, ranging from 0 (at the lower band) to 1 (at the upper band).
Multi-Timeframe Averaging:
The indicator fetches Bollinger Band data from four customizable timeframes (default: 30min, 60min, 240min, daily) using request.security() with lookahead=barmerge.lookahead_on to get the latest available data.
It calculates the normalized position (pos1, pos2, pos3, pos4) for each timeframe using f_getBBPosition().
These four positions are then averaged to produce the final avg_position:avg_position = (pos1 + pos2 + pos3 + pos4) / 4
This average is the oscillator value, which is plotted and typically oscillates between 0 and 1.
Moving Averages:
Two optional moving averages (MA1 and MA2) of the avg_position can be enabled, calculated using simple moving averages (ta.sma) with customizable lengths (default: 5 and 10).
These can be potentially used for MA crossover strategies.
What Is Being Averaged?
The oscillator (avg_position) is the average of the normalized price positions within the Bollinger Bands across the four selected timeframes. Specifically:It averages the avg_pos values (pos1, pos2, pos3, pos4) calculated for each timeframe.
Each avg_pos is itself an average of the normalized positions of the high, low, and close prices relative to the Bollinger Bands for that timeframe.
This multi-timeframe averaging smooths out short-term fluctuations and provides a broader perspective on the price's position within the volatility bands.
Interpretation
0.0 The price is at or below the lower Bollinger Band across all timeframes (indicating potential oversold conditions).
0.15: A customizable level (green band) which can be used for exiting short positions or entering long positions.
0.5: The midline, where the price is at the average of the Bollinger Bands (neutral zone).
0.85: A customizable level (orange band) which can be used for exiting long positions or entering short positions.
1.0: The price is at or above the upper Bollinger Band across all timeframes (indicating potential overbought conditions).
The colored regions and moving averages (if enabled) help identify trends or crossovers for trading signals.
Example
If the 30min timeframe shows the close at the upper band (position = 1.0), the 60min at the midline (position = 0.5), the 240min at the lower band (position = 0.0), and the daily at the upper band (position = 1.0), the avg_position would be:(1.0 + 0.5 + 0.0 + 1.0) / 4 = 0.625
This value (0.625) would plot in the orange region (between 0.85 and 0.5), suggesting the price is relatively strong but not at an extreme.
Notes
The use of lookahead=barmerge.lookahead_on ensures the indicator uses the latest available data, making it more real-time, though its effectiveness depends on the chart timeframe and TradingView's data feed.
The indicator’s sensitivity can be adjusted by changing bb_length ("Bollinger Band MA Length" in the Input tab), bb_mult ("Bollinger Band Standard Deviation," also in the Input tab), or the selected timeframes.
I’ve been having good results setting the “Bollinger Band MA Length” in the Input tab to between 5 and 10. You can use the standard 20 period, but your results will not be as granular.
This indicator has proven very good at finding local tops and bottoms by combining data from multiple timeframes. Use timeframes that are lower than the timeframe you are viewing in your price pane. Be cognizant that the indicator, like other oscillators, does occasionally produce divergences at tops and bottoms.
Any feedback is appreciated.
Overview
This indicator is an oscillator that measures the normalized position of the price relative to Bollinger Bands across multiple timeframes. It takes the price's position within the Bollinger Bands (calculated on different timeframes) and averages those positions to create a single value that oscillates between 0 and 1. This value is then plotted as the oscillator, with reference lines and colored regions to help interpret the price's relative strength or weakness.
How It Works
Bollinger Band Calculation:
The indicator uses a custom function f_getBBPosition() to calculate the position of the price within Bollinger Bands for a given timeframe.
Price Position Normalization:
For each timeframe, the function normalizes the price's position between the upper and lower Bollinger Bands.
It calculates three positions based on the high, low, and close prices of the requested timeframe:
pos_high = (High - Lower Band) / (Upper Band - Lower Band)
pos_low = (Low - Lower Band) / (Upper Band - Lower Band)
pos_close = (Close - Lower Band) / (Upper Band - Lower Band)
If the upper band is not greater than the lower band or if the data is invalid (e.g., na), it defaults to 0.5 (the midline).
The average of these three positions (avg_pos) represents the normalized position for that timeframe, ranging from 0 (at the lower band) to 1 (at the upper band).
Multi-Timeframe Averaging:
The indicator fetches Bollinger Band data from four customizable timeframes (default: 30min, 60min, 240min, daily) using request.security() with lookahead=barmerge.lookahead_on to get the latest available data.
It calculates the normalized position (pos1, pos2, pos3, pos4) for each timeframe using f_getBBPosition().
These four positions are then averaged to produce the final avg_position:avg_position = (pos1 + pos2 + pos3 + pos4) / 4
This average is the oscillator value, which is plotted and typically oscillates between 0 and 1.
Moving Averages:
Two optional moving averages (MA1 and MA2) of the avg_position can be enabled, calculated using simple moving averages (ta.sma) with customizable lengths (default: 5 and 10).
These can be potentially used for MA crossover strategies.
What Is Being Averaged?
The oscillator (avg_position) is the average of the normalized price positions within the Bollinger Bands across the four selected timeframes. Specifically:It averages the avg_pos values (pos1, pos2, pos3, pos4) calculated for each timeframe.
Each avg_pos is itself an average of the normalized positions of the high, low, and close prices relative to the Bollinger Bands for that timeframe.
This multi-timeframe averaging smooths out short-term fluctuations and provides a broader perspective on the price's position within the volatility bands.
Interpretation
0.0 The price is at or below the lower Bollinger Band across all timeframes (indicating potential oversold conditions).
0.15: A customizable level (green band) which can be used for exiting short positions or entering long positions.
0.5: The midline, where the price is at the average of the Bollinger Bands (neutral zone).
0.85: A customizable level (orange band) which can be used for exiting long positions or entering short positions.
1.0: The price is at or above the upper Bollinger Band across all timeframes (indicating potential overbought conditions).
The colored regions and moving averages (if enabled) help identify trends or crossovers for trading signals.
Example
If the 30min timeframe shows the close at the upper band (position = 1.0), the 60min at the midline (position = 0.5), the 240min at the lower band (position = 0.0), and the daily at the upper band (position = 1.0), the avg_position would be:(1.0 + 0.5 + 0.0 + 1.0) / 4 = 0.625
This value (0.625) would plot in the orange region (between 0.85 and 0.5), suggesting the price is relatively strong but not at an extreme.
Notes
The use of lookahead=barmerge.lookahead_on ensures the indicator uses the latest available data, making it more real-time, though its effectiveness depends on the chart timeframe and TradingView's data feed.
The indicator’s sensitivity can be adjusted by changing bb_length ("Bollinger Band MA Length" in the Input tab), bb_mult ("Bollinger Band Standard Deviation," also in the Input tab), or the selected timeframes.
Open-source script
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.
Disclaimer
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.
Open-source script
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.
Disclaimer
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.