TradingView indicator calculations

Gopalakrishnan Range Index: calculate the range before using a threshold

The Gopalakrishnan Range Index (GAPO) expresses a rolling price range as ln(highest high − lowest low) / ln(N), where N is the number of bars. For a fixed window and price unit, a larger range produces a larger reading. The raw formula is sensitive to price units: quoting the same prices in cents instead of dollars changes GAPO. It supplies no trade direction and no universal threshold for comparing assets.

See the decision guide

Define the calculation and its source prices

The January 2001 Stocks & Commodities Traders' Tips page provides high/low implementations of Jayanthi Gopalakrishnan's index. Let H be the highest high and L the lowest low across N consecutive bars, including the evaluated bar. Set R = H − L and G = ln(R) / ln(N). Natural logs and base-10 logs give the same ratio when both numerator and denominator use the same base.

  • Use an integer N ≥ 2 and a positive range. This page waits for N complete, valid high/low observations; it does not calculate from a shorter initial window.
  • The same 2001 collection also contains a close-only implementation. Highest close minus lowest close can differ from highest high minus lowest low. A script title alone does not identify which version you have.
  • GAPO is a logarithm ratio, not ln(R/N) and not an average of individual candle ranges. Do not substitute either expression when checking parity.

Recalculate a five-bar example

These hypothetical completed bars are quoted in dollars. N = 5; rows run from oldest to newest. No result represents market data or a trading backtest.

  • H = 107, L = 99 and R = 8. Therefore G = ln(8)/ln(5) = 1.292030, rounded to six decimals.
  • The highest high and lowest low come from different bars. Averaging the five individual ranges would give 3.4, which is not the input to this GAPO calculation.
  • Append a sixth bar with high 106 and low 102. The new five-bar window excludes bar 1: H remains 107, L becomes 100, and R falls to 7. GAPO falls even though the sixth bar created neither a new high nor a new low.
  • For a fixed N, GAPO is a monotonic transformation of the rolling range. Its rise or fall records range expansion or contraction, including changes caused by old extrema leaving the window.
BarHigh ($)Low ($)
110299
2104101
3103100
4107102
5106103

Why dollars and cents produce different readings

Derivation from the formula: multiplying every price by a positive constant c multiplies R by c. The new reading is G′ = G + ln(c)/ln(N). Adding the same constant to every price leaves R unchanged. GAPO is therefore invariant to an additive shift, but not to a multiplicative change of scale.

  • The dollar-to-cent change adds ln(100)/ln(5) = 2.861353. A hypothetical rule G > 2 is false in dollars and true in cents for exactly the same economic data.
  • More generally, G > T is equivalent to R > N^T in the chosen price unit. At N = 5, T = 2 means a numeric range above 25: $25 and 25 cents are different conditions.
  • Changing a chart between linear and logarithmic display does not itself convert the raw high/low inputs. Changing the quote currency, feed scale or adjusted price series can change them.
  • A common numeric threshold across assets therefore needs separate justification. Record the units, window, timeframe and data adjustments; do not read equal GAPO values as equal percentage risk.
Same five bars expressed inNumeric range RGAPO
Dollars81.292030
Cents (100 × dollars)8004.153383
Hundreds of dollars (0.01 × dollars)0.08-1.569323

Separate a longer window from a larger range

Changing N affects both the extrema window and the denominator. Even if the wider window doubles the range, the result can fall. In these hypothetical comparisons, the ten-bar window contains the five-bar sample plus five earlier bars.

  • The first comparison isolates the denominator. The second changes both inputs. Neither proves that one window detects trends better.
  • Five daily bars and five hourly bars have the same denominator but cover different observations. Compare like-for-like settings before assessing any historical distribution.
  • A percentile rank within one instrument's history can describe relative range conditions under fixed settings. It adds a reference window and a tie rule, so it is a derived statistic rather than raw GAPO. Equal percentiles still do not imply equal volatility or expected returns.
WindowRange in dollarsGAPO
5 bars81.292030
10 bars; no older extreme outside the range80.903090
10 bars; older extreme doubles the range161.204120

Handle invalid windows and distinguish other indicators

The mathematical domain matters more than the color of the line. The following policies make an implementation reviewable; they do not establish a profitable signal.

  • Replacing R with a small positive floor prevents a log error but invents a finite reading for a flat window. If a script does this, document the floor and its unit dependence instead of claiming exact raw-formula parity.
  • ATR smooths true ranges and uses the previous close when measuring gaps. GAPO uses two extrema over the whole window. Its value is not ATR in a different unit.
  • A path-based Fractal Dimension Index examines intermediate movements under its own normalization. Two windows can share H, L and N yet have very different internal paths; raw GAPO gives them the same result.
  • A range breakout rule compares a selected price with a defined prior boundary. GAPO alone neither selects that boundary timing nor identifies whether price broke upward or downward.
CaseConsequencePolicy for this calculation
R = 0ln(0) is undefined.Return no value; suppress alerts.
0 < R < 1G is negative.Keep the valid negative value.
R = 1G = 0.Do not interpret zero as zero movement.
N = 1ln(1) = 0.Reject the setting.
Missing or invalid high/lowThe required window is incomplete.Wait for N consecutive valid observations.
Current bar still openIts high and low can change.Confirm classifications at chart-bar close.

Verify a TradingView plot before requesting alerts

TradingView hosts public GAPO scripts, including the open-source publication by everget. Record the chosen author and version, high/low versus close-only source, N, symbol, timeframe, session and adjustment settings. Compare H, L, R and G on completed bars; matching only the visible line color cannot establish numerical agreement.

  • Give the Pine Script AI Coding Agent the public formula and the five-bar fixture. Ask for separate diagnostic values for H, L, R and G, a minimum length of 2, full-window initialization, and explicit missing/zero-range handling.
  • Request a syntax check after drafting, then compare TradingView values with the arithmetic example. Syntax checks cannot establish formula correctness, feed parity or predictive accuracy.
  • For a hypothetical entry into G > T, require valid previous G ≤ T and current G > T at the chart-bar close. Keep the threshold in the recorded price units. A persistent state above T should not masquerade as a new crossing every bar.
  • This page uses chart-timeframe inputs. Adding higher-timeframe data requires a separate confirmation rule; a closed chart bar does not confirm a still-open higher-timeframe bar.
  • Review the public algorithm and source you are permitted to use. This workflow does not recover protected scripts. Position sizing, entries, exits and costs require separate specifications and tests.
Where Pineify fits

Pine Script AI Coding Agent

Draft a GAPO script from the stated formula, window policy and numerical fixtures. Inspect the generated source and verify its values before creating alerts.

Draft a GAPO calculation

Frequently asked questions

Educational calculations, not investment advice. All sample prices and thresholds are hypothetical. No strategy performance has been tested, and GAPO does not establish trade direction or expected returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.