mardi 6 septembre 2016

Average line help

Hi friends,

Help me to write an AFL to plot a moving average difference line.

I want to plot this “Average line” on lower panel not on price chart.

Formula for this “Average line” = simple moving average – Lagged Moving average.

Simple moving average = A simple moving average with “n” days average plotted upto last price bar.

Lagged Moving average = A simple moving average with “n” days average plotted “n/2” days before last price bar. For eg : if it is 14day moving average the last plotted point will be 7 days before last price bar..
The calculation of both simple and lagged moving average is the same just lagged moving average is plotted n/2 days back.

I have one afl for this :

n = Param("Length",14,2,200,1,1);
n2 = Param("Length",28,2,200,1,1);
MA1 = MA(C,n);
MA2 = MA(C,n2);
Plot(MA1-MA2),"AL",ParamColor("color",colorcycle),ParamStyl e("style"),0,0,-(n-1)/2);

The problem here is both the moving averages are shifted back and then I am getting the difference. But I want is only one average MA2 to be shifted back. If I can change “MA2” formula and make it shift “n” bars back it may work.

Thanks in adv.


Average line help

Aucun commentaire:

Enregistrer un commentaire