OPEN-SOURCE SCRIPT

Range Profile Oscillator

4 639
█ OVERVIEW
Range Profile Oscillator is a momentum oscillator that analyzes the position of price relative to a dynamic price range profile (Range Profile). Within a defined historical window the script builds a profile of price activity, locates its point of highest activity concentration and the boundaries of the overbought and oversold zones, then measures how far the current price has moved away from this equilibrium area.
Unlike traditional oscillators, the reference levels are neither fixed nor based solely on price changes. They are calculated from the distribution of price activity across the entire analyzed range, so they automatically adapt to the current market structure. As a result, signals appear only when price truly leaves the area considered typical for recent market activity.
The indicator generates BUY and SELL signals when the oscillator line breaks out beyond the dynamic Overbought (OB) and Oversold (OS) zones. It can also color candles according to the current oscillator direction, highlight the background on breakouts, and automatically plot Entry, Stop Loss and Take Profit levels using either ATR or a fixed percentage risk.
The result is a tool that combines price location analysis, momentum and adaptive market equilibrium levels. This helps distinguish ordinary price fluctuations from moments when the market genuinely breaks out of its characteristic range.

█ CONCEPTS
Range Profile
The foundation of the indicator is the Range Profile — an analysis of the distribution of price activity within the selected historical range. The entire price range is divided into many small intervals (bins), and the candle activity falling into each of them is counted. This creates a profile that shows the levels where price spent the most time.
Instead of assuming that the market center lies exactly halfway between the highest and lowest price, the indicator locates it at the level of highest activity concentration. This provides a much more accurate reflection of true market equilibrium.

Dynamic equilibrium line (Midline)
The Midline represents the level around which the market spent the most time in the analyzed period. The oscillator value is calculated from this level.
When price is close to the Midline it remains in the equilibrium area. The farther it moves away from this level, the stronger the momentum becomes and the higher the probability of entering the overbought or oversold zone.

Dynamic Overbought and Oversold zones
The overbought and oversold boundaries are not fixed. They are derived from the current market profile and automatically expand or contract with changes in volatility and price structure.
This allows the indicator to adapt its sensitivity to market conditions. In quiet markets the zones become narrower; during high volatility they widen, reducing the number of random signals.

Price location oscillator
The oscillator line shows how far the current price is from the point of highest activity concentration (Midline) relative to the width of the entire profile.
Values near zero indicate trading inside the equilibrium area, while a rising or falling oscillator reflects an increasing distance from the typical range. Crossing the OB or OS boundaries means the market has reached an extreme position relative to its current profile.

Breakout signals
A BUY signal is generated when the oscillator breaks above the Overbought zone; a SELL signal appears when it breaks below the Oversold zone.
An optional signal filter prevents repeated signals in the same direction. A new BUY can appear only after a previous SELL (and vice versa), which limits the number of consecutive same-direction signals during strong trends.

Momentum visualization
The color of the oscillator line and, optionally, the candles reflects the current market state:
* bullish color indicates a breakout above the Overbought zone,
* bearish color indicates a breakout below the Oversold zone,
* neutral color shows that price is still inside the normal range.

In addition, the gradient and background highlighting visualize the strength of the breakout beyond the profile boundaries, making the most dynamic moves immediately visible on the chart.

█ FEATURES
Calculation Settings
• Lookback Bars – number of historical bars used to build the range profile, determine the Midline and the OB/OS channel boundaries
• OB/OS Level – distance from the Midline (as a % of half the channel width) that defines the Overbought and Oversold zones; a breakout beyond this level triggers a signal

Signals
• Highlight Background on Breakout – colors the chart background when the oscillator line breaks above/below the OB/OS channel
• Background Highlight Transparency – adjusts the transparency of the background breakout highlight
• Show BUY/SELL Labels – plots BUY or SELL labels on the main chart whenever a breakout signal fires
• Signal Filter – blocks repeated signals in the same direction (a new BUY only after a SELL and vice versa)

Appearance
• Show Breakout Gradient – fills the area between the signal line and the OB/OS boundary with a gradient whenever price is outside the channel
• Color Candles by Signal Line – colors the main-chart candles using the same color as the signal line (bullish / bearish / neutral)

Colors
• Bullish Color, Bearish Color, Neutral Color – three consistent colors used throughout the indicator for lines, fills, labels, signals and candles

TP/SL
• Show TP/SL – automatically draws Entry, Stop Loss and Take Profit levels on the main chart whenever a breakout signal fires
• SL = ATR × instead of % – choice between an ATR-based stop-loss (ATR × multiplier) or a fixed percentage of the entry price
• ATR Period and SL ATR Multiplier – parameters for the ATR-based stop-loss
• SL % from Entry – percentage stop-loss distance (used when ATR is disabled)
• TP1 RR / TP2 RR / TP3 RR – Risk:Reward multiples for the three Take Profit levels
• Independent on/off switches for displaying SL, TP1, TP2 and TP3

Alerts
• Alert on breakout above the Overbought zone
• Alert on breakout below the Oversold zone

█ APPLICATIONS
Identifying breakouts beyond the equilibrium area
The indicator helps distinguish ordinary price fluctuations inside the typical range from moments when the market leaves the zone of highest activity. Signals appear only when the oscillator breaks the dynamic OB/OS boundaries.

Breakouts as a potential start of a stronger move
Breakouts beyond the OB/OS zone often mark the beginning of a stronger move or a new trend, so the signals can serve a role similar to classic trend indicators. They should not, however, be treated automatically as entry points. Before acting it is advisable to examine the broader context: whether the signal occurs near a significant support/resistance zone and whether it is confirmed by other technical analysis tools (e.g. market structure, momentum, volume).

Risk management directly on the chart
The automatic Entry, SL and TP levels allow a quick assessment of the potential risk-to-reward ratio for each signal. You can use either ATR or a fixed percentage, adjusting the parameters to your trading style and the instrument’s volatility.

Visual assessment of momentum strength
The color of the oscillator line, the candles and the breakout gradient immediately show whether the market is still inside the equilibrium zone or has already entered overbought/oversold territory. Background highlighting further draws attention to the moment of the breakout.

Complementing other analysis methods
Range Profile Oscillator signals can act as a filter or confirmation for strategies based on market structure, support/resistance, order flow or classic momentum oscillators.

Matching lookback to trading style
The lookback value should be chosen according to the timeframe and trading horizon. A shorter lookback reacts faster to local structural changes; a longer one better reflects the broader market context.

█ NOTES
• The Midline and OB/OS zones are recalculated on every bar from the most recent lookback window — the indicator automatically adapts to the current market structure.
• BUY/SELL signals and alerts mark the moment price breaks out of the current range profile. They are not automatic entry points — before taking a decision it is recommended to check alignment with other tools (market structure, momentum, volume, etc.).

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.