I need help about my study (for a daily chart)
I want to insert in the study a 2 year moving average (geometric mean) of the next-day returns following an up day and a down day
here is the code:
Code: Select all
Inputs :
Price(Close);
Variables:
PriceUp(False), PriceDn(False),
NextDayReturnUp(0), NextDayReturnDn(0);
PriceUp = Price[1] > Price[2];
PriceDn = Price[1] <= Price[2];
If PriceUp then
begin
NextDayReturnUp = ((Price-Price[1])/Price[1])*100;
end;
If PriceDn then
begin
NextDayReturnDn = ((Price-Price[1])/Price[1])*100;
end;
Plot1( NextDayReturnUp, "NextDayReturnUp" );
Plot2( NextDayReturnDn, "NextDayReturnDn" );
plot3(0, "Zero");
Code: Select all
{ Geometric Mean }
Inputs:
Price(NumericSeries), Length(NumericSimple);
Variables:
Product(0), ix(0);
Product = 1;
For ix = 0 to Length-1
begin
Product = Product * Price[ix];
end;
GeometricMean = Power(Product, 1/Length);
Nuno