TradingView indicator guides

RAVI indicator: measuring moving-average separation

The Range Action Verification Index (RAVI) measures the gap between a fast and a slow moving average as a percentage of the slow average. Its absolute version measures separation; its signed version also shows which average is higher. A threshold is a market-state rule you choose, not proof that a breakout will continue.

Signed RAVI = 100 × (fast MA − slow MA) / slow MA

Absolute RAVI = 100 × |fast MA − slow MA| / slow MA

These interpretations assume a positive slow MA. The example below starts with 7/65 SMAs and lets you switch between both versions.

One denominator, two meanings

Let F be the 7-bar SMA of close and S the 65-bar SMA of close. Subtract S from F to get a price-unit gap. Divide by S to express that gap relative to the slower average, then multiply by 100 for percent. Taking the absolute value of the numerator removes direction when S is positive.

The Wealth-Lab implementation exposes both absolute and signed calculations. Pineify's existing RAVI indicator uses the absolute calculation. A script with a negative threshold must therefore be checked for its actual output convention.

Hypothetical MA snapshots; threshold T = 3%, with a strict greater-than rule. These are arithmetic examples, not observed trades.
CaseFast SMASlow SMASignedAbsoluteFilter state
Small gap100.5100+0.5%0.5%Below threshold
Positive separation104100+4%4%Above threshold
Negative separation96100-4%4%Above threshold
Exact boundary103100+3%3%Not above threshold
Same gap, higher base204200+2%2%Below threshold

For F = 104 and S = 100, the gap is 4 and RAVI is 4%. For F = 204 and S = 200, the same gap is only 2%. Multiplying an entire price history by a positive constant leaves the percentage unchanged; adding a constant does not. Percentage normalization also does not equalize volatility or trading costs.

The +4% and -4% rows both pass an absolute filter. To recover direction, compare F with S or retain signed RAVI. A small gap is consistent with a range, but can also occur while a trend starts or reverses. These snapshots cannot establish the full price path.

Separate the threshold state from an entry event

With T = 3%, the state rule is |signed RAVI| > 3. The signed equivalent is RAVI > +3 or RAVI < -3. A new expansion event requires the previous absolute value to be at or below 3 and the current value to be above 3. Staying above 3 for ten bars is one crossing, not ten new crossings.

  1. Choose the source, MA types, lengths, chart timeframe and session before comparing scripts. This example uses SMA for both averages; replacing them with EMA creates a different variant.
  2. Write the inequality explicitly. A value exactly equal to 3 does not pass this example's strict rule. A formula already multiplied by 100 uses 3 for 3%, not 0.03.
  3. Define an independent entry, exit and position-size rule. A separation threshold supplies neither an order price nor a stop level.
  4. Compare the same strategy with and without the filter on later, unused data. Include commission, slippage, drawdown and trade count; fewer trades alone do not demonstrate an improvement.

A rising absolute RAVI means a wider relative gap. It can rise during a decline, and it can fall while both averages are still rising. Neither slope nor color replaces the signed comparison.

RAVI Pine Script v6 for TradingView

Copy this educational indicator into the Pine Editor, save it and select Add to chart. It plots absolute RAVI by default. Turn off Absolute RAVI to show direction and the negative threshold. The Data Window exposes both averages and both RAVI values for manual comparison. The script does not place trades.

Pine Script v6

Paste into a new indicator in the TradingView Pine Editor.

//@version=6
indicator("RAVI: signed or absolute", overlay=false, precision=3)
source = input.source(close, "Source")
fastLength = input.int(7, "Fast SMA length", minval=1)
slowLength = input.int(65, "Slow SMA length", minval=2)
absoluteMode = input.bool(true, "Absolute RAVI")
threshold = input.float(3.0, "Separation threshold (%)", minval=0.001, step=0.1)
if fastLength >= slowLength
    runtime.error("Fast length must be smaller than slow length.")
fastMA = ta.sma(source, fastLength)
slowMA = ta.sma(source, slowLength)
if not na(slowMA) and slowMA <= 0
    runtime.error("This example requires a positive slow SMA.")
signedRavi = slowMA > 0 ? 100.0 * (fastMA - slowMA) / slowMA : na
absoluteRavi = math.abs(signedRavi)
ravi = absoluteMode ? absoluteRavi : signedRavi
aboveThreshold = absoluteRavi > threshold
crossedThreshold = ta.crossover(absoluteRavi, threshold)
confirmedExpansion = crossedThreshold and barstate.isconfirmed
plot(ravi, "RAVI (%)", color=color.blue, linewidth=2)
hline(0, "Zero", color=color.gray)
hline(threshold, "Positive threshold", color=color.orange)
plot(absoluteMode ? na : -threshold, "Negative threshold", color=color.orange)
plot(fastMA, "Fast SMA", display=display.data_window)
plot(slowMA, "Slow SMA", display=display.data_window)
plot(signedRavi, "Signed RAVI (%)", display=display.data_window)
plot(absoluteRavi, "Absolute RAVI (%)", display=display.data_window)
bgcolor(aboveThreshold and barstate.isconfirmed ? color.new(color.orange, 90) : na)
plotshape(confirmedExpansion, title="Separation crossed threshold at close", style=shape.circle, location=location.bottom, color=color.orange, size=size.tiny)
alertcondition(confirmedExpansion, "RAVI separation at close", "Absolute RAVI crossed above its threshold on a confirmed chart bar.")

On continuous close data, the 65-bar SMA needs 65 observations before a result is available. Do not replace that warm-up with zero. The line updates on the open bar; the marker and alert condition wait for barstate.isconfirmed. To receive notifications, create an alert in TradingView using the script's RAVI separation condition.

Where the interpretation fails

  • A zero denominator makes RAVI undefined. A negative slow MA reverses the usual sign interpretation and makes the numerator-absolute formula negative. This example stops for a nonpositive slow MA; it is intended for positive-price series.
  • A very small positive denominator can produce an extreme percentage. RAVI is not capped at 100, and its value is not a confidence score.
  • Moving averages retain older prices. Separation can stay above the threshold after price has reversed, while a brief jump can create a threshold crossing that soon fails.
  • A 65-bar window means 325 chart minutes on a five-minute chart and 65 trading bars on a daily chart. Session gaps and missing bars prevent treating those as interchangeable calendar spans.
  • There is no supported universal threshold for every symbol. Testing many thresholds and retaining only the best historical result can fit noise.

Educational information, not investment advice. Syntax validity and historical examples do not establish profitability or guarantee future results.

RAVI is different from both RVI indicators

RAVI stands for Range Action Verification Index. Relative Vigor Index compares smoothed close-minus-open movement with high-minus-low ranges. Relative Volatility Index uses standard-deviation-based movement and a 0 to 100 scale. Neither uses the RAVI fast-minus-slow percentage formula. See TradingView's vigor and volatility definitions.

RAVI questions

Sources and further checks

Reviewed October 17, 2026. Numerical cases above are constructed formula checks. No trading performance is claimed.

For another percentage MA-gap calculation, compare the Percentage Price Oscillator. Match the MA type and lengths before comparing values; its signal line adds a separate smoothing step.

Turn the filter into a testable script

Pineify's Pine Script AI Coding Agent can draft and edit code from your instructions and provides a syntax-checking tool. Specify absolute or signed output, the threshold inequality, closed-bar timing and your separate entry and exit rules. Review the generated code and test it in TradingView.

Use 7/65 SMAs of close. Keep signed RAVI in the Data Window and use absolute RAVI above 3% only as a filter. Keep my existing entry and exit rules separate. Explain what happens at exactly 3% and check the script syntax.

This page's example is available to copy. Product access depends on your account and plan. Generated code still needs formula review and strategy testing.

Explore Pine Script AI Coding Agent