TradingView indicator calculations

Chande VIDYA indicator: verify the adaptive weight

The Chande VIDYA indicator, or Variable Index Dynamic Average, adapts an EMA-style recursion using the absolute Chande Momentum Oscillator. For CMO expressed from -100 to 100, its current-price weight is alpha = [2 / (EMA length + 1)] × |CMO| / 100. This page covers that CMO-based version. Matching its formula alone is insufficient: two scripts must also use the same source, CMO window, starting value and missing-data policy.

Draft a VIDYA script

Separate the momentum window from the EMA factor

Let N be CMO length and L be EMA length, both positive integers. For each adjacent source-price change, collect its positive part into U and its negative magnitude into D, summing the latest N changes. When U + D > 0, CMO = 100 × (U − D) / (U + D). Set a = 2 / (L + 1), alpha = a × |CMO| / 100, and V[t] = V[t−1] + alpha × (price[t] − V[t−1]). MetaQuotes documents the equivalent ratio-scale CMO without the factor of 100.

  • The absolute normalized ratio lies from 0 to 1, so 0 ≤ alpha ≤ a ≤ 1. Each update stays between the previous VIDYA and current source price.
  • For CMO = -60 and L = 9, a = 0.2 and alpha = 0.12. Omitting the absolute value would give -0.12; omitting the division by 100 would give 12. Both violate this weight range.
  • If a script already stores CMO from -1 to 1, do not divide by 100 again. Record the scale of the intermediate value before comparing plots.
InputWhat it changesWhat it does not set
CMO length NWhich N adjacent changes enter U and DThe maximum weight a
EMA length LThe cap a = 2 / (L + 1)The number of changes in CMO
SourceThe price series used for changes and recursionA trading entry or exit

Choose a starting value and a zero-window policy

The recurrence needs a previous value, so it cannot define its own initialization. The worked example waits for N valid adjacent changes, seeds VIDYA with the current source price on that first complete window, and begins recursive updates on the next bar. This is an explicit demonstration convention, not a claim that every script named VIDYA uses that seed.

  • For identical later prices and weights, two different seeds retain a difference multiplied by (1 − alpha) on each update. A stretch of zero weights preserves the difference rather than removing it.
  • Compare the loaded history and first calculated bar when two implementations disagree. Matching length labels does not guarantee matching initialization.
ConditionPolicy used hereReason to record it
Fewer than N valid changesNo VIDYA value yetN changes require N + 1 prices.
First full windowSeed with current priceAn SMA or first-price seed starts a different series.
U = D > 0alpha = 0; keep previous VIDYAThe defined CMO is zero.
U = D = 0Set alpha to 0; keep previous VIDYAThe raw CMO ratio is 0 / 0, so this is a fallback.
Missing source observationClear the state; wait for a new full valid window and reseedMissing data is not a zero price change.

Follow a directional move into an alternating window

These are hypothetical completed-bar closes, not market data or a backtest. Use CMO length N = 3, EMA length L = 5, and therefore a = 1/3. Bars 0, 1 and 2 close at 100, 102 and 104. Bar 3 completes the first three changes and seeds VIDYA at 106. The table rounds only the displayed output to four decimals; calculations retain full precision.

  • Bar 4 contains changes +2, +2, -2. Its CMO is 100 × 2/6, so alpha = (1/3) × (1/3) = 1/9. VIDYA = 106 + (104 − 106)/9 = 105.7778.
  • Bar 7 contains +2, -2, 0. Equal positive and negative sums hold VIDYA at 105.6022 even though the window contains price movement.
  • At bar 8 the +2 change leaves the window. The remaining -2, 0, 0 gives CMO = -100 and restores the maximum weight. VIDYA moves toward 104 despite the current bar having no price change.
  • Bar 9 has three zero changes. Keeping 105.0681 follows the stated fallback; it does not mean the underlying 0 / 0 ratio is mathematically zero.
BarCloseUDalphaVIDYA
3106601/3; seed bar106.0000
4104421/9105.7778
5106421/9105.8025
6104241/9105.6022
7104220105.6022
8104021/3105.0681
9104000; fallback105.0681
10106201/3105.3788

Read the weight as directional balance

The formula responds to the balance of upward and downward movement, not simply the size of the candles. A window of +1, +1, +1 and a window of +10, +10, +10 both produce |CMO| = 100. A window of +10, -10, 0 has much more total movement than the first window, yet produces alpha = 0.

  • Scaling every change by the same positive number leaves the ratio unchanged. VIDYA weight is not a price-range or position-risk measure.
  • A directionally consistent fall can give the same weight as a rise. The update direction comes from current price minus previous VIDYA.
  • Sustained one-direction changes make alpha equal the ordinary EMA factor a. That matches the update weight, but the full line can still differ because of its earlier history and seed.

Why VIDYA and KAMA still produce different lines

TradingView documents KAMA with an efficiency ratio ER and a squared smoothing factor: [ER × (fast factor − slow factor) + slow factor]². For the same complete window of unsmoothed price changes with a positive denominator, |CMO| / 100 equals ER: U − D is the net change and U + D is the total absolute change. The distinction is how each indicator maps that ratio into a weight.

  • With KAMA fast length 2 and slow length 30, ER = 0 gives (2/31)², about 0.004162. This VIDYA gives exactly zero when U = D > 0. The comparison concerns weight, not which indicator trades better.
  • The ratio equivalence requires the same source and window. Added smoothing, different lookbacks or missing-data conventions can break that match.
CalculationWeight when the ratio is zeroWeight when the ratio is one
CMO-based VIDYA02 / (L + 1)
KAMASlow factor squaredFast factor squared

Audit a TradingView implementation before defining trades

Record the script author and version, source, chart type, session, timeframe, both lengths and seed. Inspect whether the plotted line is raw VIDYA or has extra smoothing, bands or an offset. For a custom implementation, expose U, D, CMO, alpha and VIDYA in the Data Window and compare completed bars against a hand calculation.

  • Verify a full window, a window with balanced changes, and a flat window. Use the table as a separate arithmetic fixture; live chart prices will differ.
  • An indicator can recalculate while the current bar is open. If a cross should count only at chart-bar close, specify that confirmation rule. Confirmation of a chart bar does not confirm an unfinished higher-timeframe input.
  • Give the Pine Script AI Coding Agent this specification: separate CMO and EMA inputs, explicit seed, zero-denominator and missing-data handling, intermediate diagnostic values, and the desired confirmation time.
  • Review generated source and validate its syntax, then check numerical agreement. If you add strategy orders later, define exits, order timing, position sizing, commission and slippage separately. A matching VIDYA line is not a complete strategy.
Where Pineify fits

Pine Script AI Coding Agent

Turn the VIDYA calculation contract into a script you can inspect, with separate length inputs and visible intermediate values.

Draft a VIDYA script

Frequently asked questions

Educational information, not investment advice. The prices and parameters are hypothetical calculation examples. VIDYA values do not establish expected returns or a complete trading strategy.

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.