MA crossover AFL

#1
Hai
Can anybody provide amibroker AFL (or any link) for the following condition :
If ma(c,50)is greater than ma(C,200) , then whenever ma(C,5) crosses ma(C,20) to upside, it should give buy signal and exit buy should be given when ma(C,5) crosses ma(C,20) to downside . Whenever again ma(C,5) crosses ma(C,20) to upside , it should again give buy entry.
Vice-versa should be in case of sell signal .
It would be of great help.
 
#2
_SECTION_BEGIN("");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("MA5-MA20 Crossover");
Buy = Cross( MA( Close, 5 ), MA( Close, 20 ) );
Sell = Cross( MA( Close, 20 ), MA( Close, 5 ) );
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
_SECTION_END();

Plot( MA( Close,5 ),"MA5",colorRed,styleLine);
Plot( MA( Close,20),"MA20",colorBlue,styleLine);
 
#3
Thanks for the reply.
But my requirement is different it should give buy signal only when ma(C,50) is greater than ma(C,200).
Further , it should give exit buy signal and re-entry buy signal also , if happens again if both conditions are fulfilled.
Vice-versa should be in case of Short signal.(both short entry and cover exit and re-entry of short signal ,if happens.)
 

vu22rps

Active Member
#4
Thanks for the reply.
But my requirement is different it should give buy signal only when ma(C,50) is greater than ma(C,200).
Further , it should give exit buy signal and re-entry buy signal also , if happens again if both conditions are fulfilled.
Vice-versa should be in case of Short signal.(both short entry and cover exit and re-entry of short signal ,if happens.)
I hope this solves your issue.

Code:
 _SECTION_BEGIN("");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("MA5-MA20 Crossover");
Buy = Cross( MA( Close, 5 ), MA( Close, 20 ) ) AND Cross( MA( Close, 50 ), MA( Close, 200) );
Sell = Cross( MA( Close, 20 ), MA( Close, 5 ) )AND Cross( MA( Close, 200 ), MA( Close, 50) );
;
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
_SECTION_END();

Plot( MA( Close,5 ),"MA5",colorRed,styleLine);
Plot( MA( Close,20),"MA20",colorDarkRed,styleLine);
Plot( MA( Close,50 ),"MA50",colorBlue,styleLine);
Plot( MA( Close,200),"MA200",colorDarkBlue,styleLine);

_SECTION_END();
 
#5
Thanks a lot for consideration ,but this still donot solves my problem . It donot give exit signal and re-entry signal also . I require both of these also to complete my trading setup.
 

vu22rps

Active Member
#6
Thanks a lot for consideration ,but this still donot solves my problem . It donot give exit signal and re-entry signal also . I require both of these also to complete my trading setup.


What do u mean by entry signal and exit signal, do u mean some kind of visual indication?
 
#7
Yes sir , the AFL should plot entry signal , exit signal and again re-entry signal (if happens) , both in buy condition and sell condition .
When that AFL will be runned through exploration (scan) , it would check these signals in the required scripts and we can act on those signals.
It would be of great help , if you add those one's in this AFL
 
#8
I hope this solves your issue.

Code:
 _SECTION_BEGIN("");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("MA5-MA20 Crossover");
Buy = Cross( MA( Close, 5 ), MA( Close, 20 ) ) AND [COLOR="Red"]Cross( MA( Close, 50 ), MA( Close, 200) );[/COLOR]
Sell = Cross( MA( Close, 20 ), MA( Close, 5 ) )AND [COLOR="Red"]Cross( MA( Close, 200 ), MA( Close, 50) );[/COLOR]
;
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-15);
_SECTION_END();

Plot( MA( Close,5 ),"MA5",colorRed,styleLine);
Plot( MA( Close,20),"MA20",colorDarkRed,styleLine);
Plot( MA( Close,50 ),"MA50",colorBlue,styleLine);
Plot( MA( Close,200),"MA200",colorDarkBlue,styleLine);

_SECTION_END();
use > symbol in ur formula and thats ok i guess. he only wants 50>200 not cross
 
#9
Dear all ,
Not rec'd the complete solution . Kindly help to plot (and scan) buy signal , exit signal , re-entry buy signal (in case ,if happens ).
Vice-versa for sell condition.