Master this unique indicator in TradingView's Pinescript that measures how efficiently price is trending by comparing its range to average true range.
The Gopalakrishnan Range Index (GAPO) is a technical indicator designed to measure the efficiency of a market's trend by comparing the highest high to the lowest low over a certain period, relative to the Average True Range (ATR) over the same period. Essentially, it assesses how much of the price movement within a given timeframe contributes to the overall directional trend versus just random volatility. A high GAPO value suggests a strong, efficient trend, while a low value indicates consolidation, choppiness, or a less efficient trending environment.
In Pinescript, GAPO can be a valuable tool for traders to understand the underlying "quality" of a trend, helping to identify periods where a market is likely to continue its direction with conviction versus periods where it's consolidating or experiencing significant whipsaws.
The calculation of the Gopalakrishnan Range Index involves three main components:
//@version=5
indicator("Gopalakrishnan Range Index (GAPO)", overlay=false, format=format.price) // overlay=false to plot in a separate pane
// Input for the look-back length
length = input.int(10, title="Length", minval=1)
// Calculate Highest High and Lowest Low over the period
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)
// Calculate Average True Range over the period
atrValue = ta.atr(length)
// Calculate GAPO
// Add a check to prevent division by zero if ATR is ever 0 (highly unlikely for liquid assets)
gapoValue = atrValue != 0 ? ((highestHigh - lowestLow) / atrValue) * 100 : 0
// Plot the GAPO line
plot(gapoValue, title="GAPO", color=color.blue, linewidth=2)
// Optional: Add reference lines based on historical observation or common thresholds
// These levels are not fixed and depend on the asset and timeframe.
// For example, values above 150-200 might indicate strong trends.
// Values below 50-100 might indicate consolidation.
hline(150, "Strong Trend Ref", color.green, linestyle=hline.style_dashed)
hline(100, "Mid Range Ref", color.new(color.gray, 50), linestyle=hline.style_dotted)
hline(50, "Consolidation Ref", color.red, linestyle=hline.style_dashed)
Think of GAPO as a measure of how "efficient" the trend is. A high GAPO means a significant portion of the price movement is contributing to the overall range, indicating a strong, directional move.
//@version=5
strategy("GAPO Trend Strength Strategy", overlay=true)
length = input.int(10, title="Length", minval=1)
gapoThreshold = input.float(150, title="GAPO Trend Threshold", minval=1) // Adjust based on asset
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)
atrValue = ta.atr(length)
gapoValue = atrValue != 0 ? ((highestHigh - lowestLow) / atrValue) * 100 : 0
plot(gapoValue, "GAPO", color.blue, display=display.pane_only)
hline(gapoThreshold, "Trend Threshold", color.green, linestyle=hline.style_dashed, display=display.pane_only)
// Use a simple moving average to define trend direction
trendLength = input.int(50, title="Trend MA Length", minval=10)
trendMA = ta.sma(close, trendLength)
// Long entry: Price is in uptrend and GAPO confirms strong trend
longCondition = close > trendMA and gapoValue > gapoThreshold and gapoValue > gapoValue[1]
// Short entry: Price is in downtrend and GAPO confirms strong trend
shortCondition = close < trendMA and gapoValue > gapoThreshold and gapoValue > gapoValue[1]
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exits could be based on GAPO falling below threshold or trend reversal
strategy.close("Long", when=gapoValue < gapoThreshold - 20) // Exit if trend weakens
strategy.close("Short", when=gapoValue < gapoThreshold - 20)
//@version=5
indicator("GAPO Consolidation/Breakout Signals", overlay=true)
length = input.int(10, title="Length", minval=1)
gapoLowThreshold = input.float(70, title="GAPO Low Threshold", minval=1)
gapoHighThreshold = input.float(150, title="GAPO High Threshold", minval=1)
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)
atrValue = ta.atr(length)
gapoValue = atrValue != 0 ? ((highestHigh - lowestLow) / atrValue) * 100 : 0
plot(gapoValue, "GAPO", color.blue)
hline(gapoLowThreshold, "Low Threshold", color.red, linestyle=hline.style_dashed)
hline(gapoHighThreshold, "High Threshold", color.green, linestyle=hline.style_dashed)
// Signal for potential consolidation
isConsolidating = gapoValue < gapoLowThreshold and gapoValue[1] < gapoLowThreshold
// Signal for potential breakout (from low GAPO to high GAPO)
isBreakout = gapoValue > gapoHighThreshold and gapoValue[1] <= gapoLowThreshold
bgcolor(isConsolidating ? color.new(color.fuchsia, 90) : na, title="Consolidation")
bgcolor(isBreakout ? color.new(color.orange, 90) : na, title="Breakout Imminent")
alertcondition(isConsolidating, "GAPO Consolidation", "GAPO indicates consolidation.")
alertcondition(isBreakout, "GAPO Breakout", "GAPO indicates potential breakout from consolidation.")
To get the most from the Gopalakrishnan Range Index in Pinescript:
Remember, GAPO measures the *efficiency* of price movement within its range. It does not tell you if the price is going up or down, only how strongly it's moving in a single direction.
The Gopalakrishnan Range Index (GAPO) is a unique and insightful technical indicator in Pinescript for TradingView. By quantifying the efficiency of price movement relative to its volatility, it offers traders a distinct perspective on trend strength and market phases. Whether used for confirming strong, efficient trends, identifying periods of consolidation, or signaling potential breakouts, GAPO provides valuable context to price action. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with directional indicators and price action analysis, you can leverage the GAPO to gain deeper insights into market dynamics and enhance your trading decisions.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy