Description
A VMA is an EMA that is able to regulate its smoothing percentage based on market inconstancy automatically. Its sensitivity grows by providing more weight to the ongoing data as it generates a better signal indicator for short and long-term markets.
The majority of ways for measuring Moving Averages cannot compensate for sideways moving prices versus trending markets and often generate a lot of false signals. Longer-term moving averages are slow to react to reversals in trend when prices move up and down over a long period of time. A Variable Moving Average regulates its sensitivity and lets it function better in any market conditions by using automatic regulation of the smoothing constant.
The Variable Moving Average is also known as the VIDYA Indicator. But this version is a modified concept of the VIDYA.
The Variable Moving Average was developed by Tushar S. Chande and first presented in his March, 1992 article in Technical Analysis of Stocks & Commodities magazine, in which a standard deviation was used as the Volatility Index. In his October, 1995 article in the same magazine, Chande modified the VIDYA to use his own Chande Momentum Oscillator (CMO) as the Volatility Index, the VMA code below is the result of this modification.
Github: GitHub - Doustzadeh/cTrader-Indicator
using System;
using cAlgo.API;
namespace cAlgo
{
[Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.None)]
public class VariableMovingAverage : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("VMA Periods", DefaultValue = 6, MinValue = 2)]
public int Periods { get; set; }
[Output("VMA", LineColor = "Gold", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries VMA { get; set; }
private IndicatorDataSeries pdmS, mdmS, pdiS, mdiS, iS;
protected override void Initialize()
{
pdmS = CreateDataSeries();
mdmS = CreateDataSeries();
pdiS = CreateDataSeries();
mdiS = CreateDataSeries();
iS = CreateDataSeries();
}
public override void Calculate(int index)
{
if (index < 1)
{
pdmS[index] = 0;
mdmS[index] = 0;
pdiS[index] = 0;
mdiS[index] = 0;
iS[index] = 0;
VMA[index] = 0;
return;
}
double k = 1.0 / Periods;
double pdm = Math.Max((Source[index] - Source[index - 1]), 0);
double mdm = Math.Max((Source[index - 1] - Source[index]), 0);
pdmS[index] = ((1 - k) * pdmS[index - 1]) + (k * pdm);
mdmS[index] = ((1 - k) * mdmS[index - 1]) + (k * mdm);
double s = pdmS[index] + mdmS[index];
double pdi = pdmS[index] / s;
double mdi = mdmS[index] / s;
pdiS[index] = ((1 - k) * pdiS[index - 1]) + (k * pdi);
mdiS[index] = ((1 - k) * mdiS[index - 1]) + (k * mdi);
double d = Math.Abs(pdiS[index] - mdiS[index]);
double s1 = pdiS[index] + mdiS[index];
iS[index] = ((1 - k) * iS[index - 1]) + (k * d / s1);
double hhv = iS.Maximum(Periods);
double llv = iS.Minimum(Periods);
double dif = hhv - llv;
double vI = (iS[index] - llv) / dif;
VMA[index] = ((1 - (k * vI)) * VMA[index - 1]) + (k * vI * Source[index]);
}
}
}
Doustzadeh
Joined on 20.03.2016
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Variable Moving Average.algo
- Rating: 0
- Installs: 1396
- Modified: 12/12/2021 18:05
Comments
Hi,
Do you happen to know which formula cTrader uses for VIDYA? Because that is very different from this VMO.
It's fantastic that such crucial knowledge is accessible to everyone. I make an effort to keep up with the most recent news and technological advancements because they may have an impact on the caliber of my work.
slope io