Indicator · Pine Script v6 · Own pane

RAVI: Chande Range Action Verification Index

by mihakralj

This indicator calculates the Range Action Verification Index as the absolute percentage difference between a short simple moving average and a long simple moving average of close.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code79
Settings3inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

79 lines of Pine Script v6 from lib/dynamics/ravi/ravi.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

ravi.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("RAVI: Chande Range Action Verification Index", "RAVI", overlay=false)

//@function Calculates Range Action Verification Index using short/long SMA divergence
//@param shortPeriod Lookback period for fast SMA (default: 7, ~10% of longPeriod)
//@param longPeriod Lookback period for slow SMA (default: 65, ~13 weeks daily)
//@returns RAVI value as absolute percentage divergence between short and long SMAs
//@references Tushar Chande, "Beyond Technical Analysis", Wiley, 2nd ed. (2001), pp. 66-70
//@optimized O(1) per bar via circular buffer running sums for both SMAs
ravi(simple int shortPeriod, simple int longPeriod) =>
    if shortPeriod <= 0
        runtime.error("Short period must be greater than 0")
    if longPeriod <= 0
        runtime.error("Long period must be greater than 0")
    if shortPeriod >= longPeriod
        runtime.error("Short period must be less than long period")

    // Circular buffer for short SMA (O(1) running sum)
    var array<float> shortBuf = array.new_float(shortPeriod, na)
    var int shortHead = 0
    var int shortFilled = 0
    var float shortSum = 0.0

    // Circular buffer for long SMA (O(1) running sum)
    var array<float> longBuf = array.new_float(longPeriod, na)
    var int longHead = 0
    var int longFilled = 0
    var float longSum = 0.0

    // Update short SMA buffer
    float oldShort = array.get(shortBuf, shortHead)
    if not na(oldShort)
        shortSum -= oldShort
    shortSum += close
    array.set(shortBuf, shortHead, close)
    shortFilled := math.min(shortFilled + 1, shortPeriod)
    shortHead := (shortHead + 1) % shortPeriod

    // Update long SMA buffer
    float oldLong = array.get(longBuf, longHead)
    if not na(oldLong)
        longSum -= oldLong
    longSum += close
    array.set(longBuf, longHead, close)
    longFilled := math.min(longFilled + 1, longPeriod)
    longHead := (longHead + 1) % longPeriod

    float result = na

    if shortFilled >= shortPeriod and longFilled >= longPeriod
        // Step 1: Compute short-period SMA
        float smaShort = shortSum / shortPeriod

        // Step 2: Compute long-period SMA
        float smaLong = longSum / longPeriod

        // Step 3: RAVI = |SMA(short) - SMA(long)| / SMA(long) * 100
        // Guard against division by zero (long SMA at zero)
        if math.abs(smaLong) > 1e-10
            result := math.abs(smaShort - smaLong) / math.abs(smaLong) * 100.0

    result

// ---------- Main loop ----------

// Inputs
i_short = input.int(7, "Short Period", minval=1, maxval=100, tooltip="Fast SMA period (~10% of long period; Chande default: 7)")
i_long = input.int(65, "Long Period", minval=2, maxval=500, tooltip="Slow SMA period (~13 weeks daily; Chande default: 65)")
i_threshold = input.float(3.0, "Threshold", minval=0.0, maxval=20.0, step=0.5, tooltip="Trend/range classification level (Chande default: 3%)")

// Calculation
ravi_value = ravi(i_short, i_long)

// Plot
plot(ravi_value, "RAVI", color=color.yellow, linewidth=2)
hline(i_threshold, "Threshold", color=color.new(color.red, 50), linestyle=hline.style_dashed)
hline(0, "Zero Line", color=color.new(color.gray, 70), linestyle=hline.style_dotted)

Overview

RAVI: Chande Range Action Verification Index plots that value in a separate pane with a dashed threshold line and a dotted zero line. The short period, long period, and threshold inputs change the two averages and the classification level. It does not generate trade entries or exits. Values stay empty until both moving-average windows are filled.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Short Periodint7i_short
Long Periodint65i_long
Thresholdfloat3.0i_threshold
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Colored fill

by be-thomas
65 stars

This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n

Indicator v4 Moving averagesTrend
Updated 4 days ago · GPL-3.0 GitHub repository of Colored fill

Hash Ribbons

by oguzhandilber
47 stars

This indicator plots the Hash Ribbon metric by calculating 30-day and 60-day simple moving averages of Bitcoin network hash rate data. Designed for long-term market cycle analysis, it draws in a separate pane and displays hash ribbons alongside optional buy si

Indicator v4 Moving averagesTrend Repaints
Updated 5 years ago · None stated GitHub repository of Hash Ribbons

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers