Variable index dynamic average

vidyamoving_averagesForge API 1

Exponential average that speeds up when momentum is strong.

Inputs

NameTypeDefaultRange
sourcesourceclose
period_cmoint91 to 5000
period_emaint121 to 5000

Outputs

NameTypeRequiredDescription
vidyavalueOptionalcolor theme.accent, style line, width 1
Warm-up
period_ema + period_cmo - 1 bars (20 at the defaults)
Repaints
No
Parity
MetaTrader 5, within 1e-12

Formula

CMO = (sum of up moves - sum of down moves) / (sum of up moves + sum of down moves) over period_cmo bars

alpha = 2 / (period_ema + 1) * |CMO|

VIDYA[i] = x[i] * alpha + VIDYA[i-1] * (1 - alpha)

After a gap the average starts again.