I'm trying to compare effectiveness of simple moving average with low pass filter suggested by jcl.
Code for his low pass filter:
var smoothF(int period) { return 2./(period+1); }
var LowPass(var *Data,int Period)
{
var* LP = series(*Data,3);
var a = smoothF(Period);
var a2 = a*a;
return LP[0] = (a-0.25*a2)*Data[0]
+ 0.5*a2*Data[1]
- (a-0.75*a2)*Data[2]
+ 2*(1.-a)*LP[1]
- (1.-a)*(1.-a)*LP[2];
}
First, I'd like to make sure that my spreadsheet calculates things properly.
First three closing prices are:
17.76, 17.83, 17.86.
In order to calculate low pass filter for last bar, I need low pass value for previous bar and a bar before. So first two LP values are simply security prices, then third value is calculated as in picture.
Did I make a mistake somewhere?
Code for his low pass filter:
var smoothF(int period) { return 2./(period+1); }
var LowPass(var *Data,int Period)
{
var* LP = series(*Data,3);
var a = smoothF(Period);
var a2 = a*a;
return LP[0] = (a-0.25*a2)*Data[0]
+ 0.5*a2*Data[1]
- (a-0.75*a2)*Data[2]
+ 2*(1.-a)*LP[1]
- (1.-a)*(1.-a)*LP[2];
}
First, I'd like to make sure that my spreadsheet calculates things properly.
First three closing prices are:
17.76, 17.83, 17.86.
In order to calculate low pass filter for last bar, I need low pass value for previous bar and a bar before. So first two LP values are simply security prices, then third value is calculated as in picture.
Did I make a mistake somewhere?