Bentrix Docs
HomePricingDashboard

Variable Index Dynamic Average VIDYA

Moving averagesoverlayone linein every package

An EMA whose speed is scaled by the absolute value of the Chande Momentum Oscillator, so it accelerates when gains and losses are one-sided and stalls when they cancel.

It measures trend with the speed tied to directional imbalance rather than to travel efficiency. Read the slope and the stalls; a flat VIDYA reports balance between buying and selling, not low volatility. MT5 and TA-Lib differ in how the average is started and carried, so the two lines differ by about one percent of price.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
bar —O — H — L — C —VIDYA —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. VIDYA has no value on the first 9 — the bars it needs before it can answer — and its first value stands on bar 10. Of the 291 bars that have a value, the close is above the line on 163 and below it on 128. Counting the conditions the study declares on these bars: price crosses above the line 4 times; price crosses below the line 4 times. Press a condition under the figure to see each place marked. As states rather than moments: price is above the line on 163 bars; price is below the line on 128 bars.

02Its parts, named

Warm-upno value on the first 9 bars: thestudy needs them before it cananswerThe linethe study's value, one for each barThe bars it readseach bar's close, unless you chooseanother price
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

VIDYA is a single line on the price pane: an EMA that speeds up when recent closes have moved mostly one way and slows almost to a stop when rises and falls cancel out.

It is drawn here as MetaTrader 5 computes it — with two inputs, the CMO window and the EMA period, and MetaTrader's seeding.

04Where it comes from

Tushar Chande introduced VIDYA, the Variable Index Dynamic Average, in 1992. It is an EMA whose constant is scaled, bar by bar, by the absolute value of his own CMO: when the closes of the window all moved one way the line runs at the EMA's full speed, and when their rises and falls cancelled it stops.

05The formula

An EMA with a changing constant:

VIDYAt=VIDYAt−1+αt(Pt−VIDYAt−1)
Ptthe applied price of bar t — the close by default
αtthis bar's smoothing constant, from the CMO
VIDYAt−1the average one bar before

αt is the EMA's own constant scaled by how one-sided the recent closes were: αt=2N+1|CMOt|, with the CMO taken as a fraction between 0 and 1.

06A worked example

Take the closes 20, 21, 23, 22, 24, a CMO window of 4 and an EMA period of 3 (α = 0.5).

Over the four steps the rises sum to 1 + 2 + 2 = 5 and the falls to 1. The Chande Momentum Oscillator is (5 − 1) / (5 + 1) = 0.67.

VIDYA's constant on this bar is 0.5 × 0.67 = 0.33: the line moves 33 % of the way to the new close instead of 50 %. Had the four steps been two up and two down of equal size, the oscillator would be 0 and the line would not move at all.

Carried on over the eight sample closes — 20, 21, 23, 22, 24, 25, 24, 26 — with the same windows, the line reads 22.54 on that fifth bar and 24.28 on the last, where the close is 26.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Variable Index Dynamic Average", overlay = true)
cmoLength = input.int(9, "CMO length")
emaLength = input.int(12, "EMA length")
// An exponential average whose share of the newest close is scaled by how one-sided the recent closes were.
vidya = talib.VIDYA(close, emaLength, cmoLength)
plot(vidya, "VIDYA")

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

Read as a moving average that flattens in ranges: price against the line, and the line's slope.

A line that stops in ranges. A flat VIDYA is read as closes cancelling each other out; a sloping one as closes moving one way. It fails when a range is made of long alternating runs: each run looks one-sided inside a short CMO window, and the line swings with them.

09In different markets and timeframes

VIDYA slows almost to a stop when closes alternate and speeds up when they run one way; it suits markets with clear bursts. In a slow one-way drift it follows well; in a volatile range with long alternating runs it swings.

10With other studies

Read beside the CMO of the same window — its speed control, drawn as an oscillator — and beside a plain EMA of its EMA period, which is the fastest VIDYA can be.

11What it does not tell you

!

Adapting to the past window's character is still describing the past window.

12Inputs and defaults

VIDYA (9, 12)settings card
1CMO period9
2EMA period12
3Shift0
4Applied priceClose
5TimeframeChart
6CalculationTA-Lib
7Wait for the candle to closeOn
  1. 1
    CMO period — 9The window of the Chande Momentum Oscillator that measures how one-sided the recent closes were. Shorter: the speed changes often.
  2. 2
    EMA period — 12The period of the underlying EMA — the fastest the line can be, reached when every close in the CMO window moved the same way.
  3. 3
    Shift — 0Draws every line that many candles to the right (a negative number: to the left). The values are not changed, only where they stand.
  4. 4
    Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
  5. 5
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  6. 6
    Calculation — TA-LibOr MT5, which computes it as MetaTrader 5 does — see the calculation convention below.
  7. 7
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

What each input changes

  • ShiftDraws the line that many candles to the right, or to the left with a negative number. Its values do not change — only the candle each one stands on — so a shifted average is compared with a later price than the one it was computed at.
  • In useCMO window 9, EMA period 12 are Chande's. A longer CMO window makes the speed change less often.

13Calculation convention

This is one of the studies whose result differs between the two conventions Bentrix offers. The difference is in how the first values are seeded and how the series is smoothed, so the two agree after the warm-up and differ at its start. Choose it on the settings card's Calculation row.

defaultTA-Lib

The convention of the TA-Lib library, which most charting software follows.

MT5

Computed as MetaTrader 5 computes it, so a value matches the terminal's own.

14Limits and common misreadings

It can stand completely still, which an ordinary average never does; price can then drift far from it.

Two periods. A VIDYA is described by both; quoting only one is ambiguous.

15Conditions an alert or a strategy can watch

price crosses above the line eventprice crosses below the line eventprice is above the line stateprice is below the line state

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

16Practise it in the laboratory

Put VIDYA (9, 12) and EMA 12 on one chart and replay a tight range followed by a trend; note where VIDYA stands still and when it lets go.

Open the laboratory

18In Bentrix

  • From the menu: a chart's Indicators button › Moving averages › VIDYA, or type VIDYA in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

19From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "vidya"}).

The study, as a chart files it

This is a new VIDYA’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "talib",
  "kind": "vidya",
  "settings": {
    "cmo": 9,
    "ema": 12,
    "shape": "vidya"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "talib",
      "kind": "vidya",
      "settings": {
        "cmo": 9,
        "ema": 12,
        "shape": "vidya"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "talib", "kind": "vidya", "settings": {"cmo": 9, "ema": 12, "shape": "vidya"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "vidya", "settings": { "cmo": 9, "ema": 12, "shape": "vidya" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "vidya", ["settings"] = new Dictionary<string, object?> { ["cmo"] = 9, ["ema"] = 12, ["shape"] = "vidya" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "vidya", "settings": map[string]any{"cmo": 9, "ema": 12, "shape": "vidya"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "talib", "kind", "vidya", "settings", obj("cmo", 9, "ema", 12, "shape", "vidya"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "vidya"}, {"settings", Json::Object{{"cmo", 9}, {"ema", 12}, {"shape", "vidya"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "talib", "kind" => "vidya", "settings" => Dict{String,Any}("cmo" => 9, "ema" => 12, "shape" => "vidya")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "vidya", settings = list(cmo = 9, ema = 12, shape = "vidya")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "vidya", "settings": {"cmo": 9, "ema": 12, "shape": "vidya"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
lineWhat it is
Mainline

In a strategy

Filed under a key of your choice in a strategy document’s studies — here vidya: {"vidya": {"applied": "close", "convention": "talib", "kind": "vidya", "settings": {"cmo": 9, "ema": 12, "shape": "vidya"}}} — its rules can name:

WriteWhat it is
vidyaits main line, as a value in a compare
{"cond": "vidya:price.cross_up"}a condition it declares itself
{"cond": "vidya:price.cross_down"}a condition it declares itself
{"cond": "vidya:price.above"}a condition it declares itself
{"cond": "vidya:price.below"}a condition it declares itself

20Sources

  1. Chande, Tushar S. "Adapting Moving Averages to Market Volatility." Technical Analysis of Stocks & Commodities, March 1992.
  2. Ehlers, John F. Rocket Science for Traders. Wiley, 2001.
  3. Ehlers, John F. "FRAMA — Fractal Adaptive Moving Average." Technical Analysis of Stocks & Commodities, October 2005.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed