Angle of 50 period EMA

Hi Team ,

Please help in coding below , i tried lineregslope but no luck ..

  1. Buy = angle of 50 EMA > 30 degree and stochastic(15,3) < 30
  2. Sell = angle of 50 EMA < - 30 degree and stochastic(15,3) > 70

@puneet_gaur2k1 you are making a common beginner's mistake. The angle of a line on a chart of Price vs Time will change every time you zoom in or zoom out of the chart. Read the following.

Your rules can be quantified in a different way.

You must have read that someplace and thought the author knew what he was talking about. That rule is essentially telling you the 50 EMA is increasing at a rate above a certain threshold. So quantify that and experiment with different threshold's to see what works.

6 Likes

@puneet_gaur2k1 ROC or the Rate of Change indicator is essentially the same as slope of a line. Here is a simple AFL that should do what you want:

Slope = ROC( EMA( Close, 50 ), 5);//measuring slope over 5 bars, adjust as needed
SlopeAbove = Slope > 0.2;//adjust ROC limit as needed
SlopeBelow = Slope < - 0.2;//adjust ROC limit as needed
Stochastic = StochK( 15 , 3);
StochBelow = Stochastic < 30;
StochAbove = Stochastic > 70;
Buy = SlopeAbove AND StochBelow;
Sell = SlopeBelow AND StochAbove;
Short = Cover = 0;

Plot( C, "Price", colorDefault, styleCandle );
Plot (EMA( Close, 50 ),"50EMA",colorBrown,styleLine);

Plot (Slope,"Slope",colorAqua,styleLine|styleThick|styleOwnScale);
Plot (Stochastic,"Stochastic",colorBlue,styleLine|styleOwnScale);
8 Likes

You can see here in these two images both ending on the same date, the angle of the EMA line in red, looks like it is less than 30 degrees in the top picture, but when you zoom out the chart for the bottom image, it looks steeper than 30 degrees. However in both images, the ROC (in light blue) is unaffected by the zoom and reads the same at 0.344815

image
image

1 Like

My sincere thanks to you sir !!:+1:

2 Likes