I'm trying to add Weighted Moving average into my code and got abit stuck. I don't know how to proceed. If anyone out there can provide a few tips, it would be greatly appreciated.
Here is the partial code:
private void SetPlot(int index,MATYPE matype, int period){
if(matype == MATYPE.EMA)
Values[index].Set(Ema(index,period));
else if (matype == MATYPE.SMA)
Values[index].Set(Sma(index,period));
else if (matype == MATYPE.WMA)
Values[index].Set(Wma(index,period));
}
private double Sma(int index, int period){
double value;
if (CurrentBar == 0) value = (Input[0]);
else{
double last = Values[index][1] * Math.Min(CurrentBar, period);
if (CurrentBar >= period)
value = ((last + Input[0] - Input[period]) / Math.Min(CurrentBar, period));
else
value = ((last + Input[0]) / (Math.Min(CurrentBar, period) + 1));
}
return value;
}
private double Ema(int index, int period){
return CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + period)) + (1 - (2.0 / (1 + period))) * Values[index][1];
}
private double Wma(int index, int period){
// here is where i am stuck..........................
thanks
Comment