Need AFL for Converging EMAs

#1
Hi,

I heard there are some good AFL coders in this forum. Please someone help me in coding AFL for exploring stocks whose EMAs are converging. I started writing this AFL which tells whether today is the day of closest convergence (in the last 130 days). I am attaching a screenshot. I want to know if this be improved further. But what I really need is a similar AFL which works on weekly timeframe. Thanks.

a1 = abs( EMA(C,12) - EMA(C,26) );
a2 = abs( EMA(C,26)-EMA(C,39) );
a3 = abs( EMA(C,12)-EMA(C,39) );

SumOfGaps = (a1+a2+a3);
AvgOfEMAs = ( EMA(C,12) + EMA(C,26) + EMA(C,39) )/3 ;

Squeeze = (SumOfGaps/AvgOfEMAs)*100;

Filter = LLV(Squeeze, 130) == Squeeze;

AddColumn(C,"Price");
AddColumn(Squeeze, "Squeeze");
 

Attachments

Romeo1998

Well-Known Member
#2
Dear friend pennywize,
u can change the convergence distance from parameters :happy:
I have not added the 130 days Filter :D ( bcoz currently i do not know how to do that :D )
this code will plot the emas n also a white arrow on the chart to show convergence
( just for visual confirmation :D )
Note -- in Analysis window, in settings, change periodicity to Weekly n click on explore to scan in Weekly timeframe :happy:
here is the code :happy:
Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

//parameter for setting distance between EMAs :)
af=Param("Param",2,0.1,1000,0.1);

//difference between EMAS
a1 = abs( EMA(C,12) - EMA(C,26) );
a2 = abs( EMA(C,26)-EMA(C,39) );
a3 = abs( EMA(C,12)-EMA(C,39) );

//conditions when difference between EMAs is true :)
c1=a1<=af;
c2=a2<=af;
c3=a3<=af;
cond = c1 AND c2 AND c3;

//plotting for confirmation :)
Plot(EMA(C,12),"Ema 12",colorYellow,styleLine);
Plot(EMA(C,26),"Ema 26",colorred,styleLine);
Plot(EMA(C,39),"Ema 39",colorblue,styleLine);
PlotShapes(cond*shapeUpArrow,colorWhite,0,L,-30);

Filter = cond;
AddColumn(IIf(cond,EMA(C,12),Null), "EMA 12",1.2);
AddColumn(IIf(cond,EMA(C,26),Null), "EMA 26",1.2);
AddColumn(IIf(cond,EMA(C,39),Null), "EMA 39",1.2);
AddColumn(IIf(cond,af,Null), "Distance between EMAs",1.2);
:happy:
 
Last edited:

Similar threads