Avoid False signals AFL amibroker

Hello Sir,

I have AFL which is testing phase, I have observed getting a false signal’s after milliseconds disappearing (BUY Sell arrows ) so that getting in losses after certain milliseconds. Kindly help me buy or sell signal should generate once cross and stay for and be for certain milliseconds.

Bellow is the sample code.


_SECTION_BEGIN("HA");
a=20;
GraphXSpace=5;
p=30;
Order=0;
p = Param("p",30,2,100,1);
Om=DEMA(O,p);
hm=DEMA(H,p);
lm=DEMA(L,p);
Cm=DEMA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1), 1);
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
slope = Param("slope",2,2,100,1);
Color20= IIf(LinRegSlope(MA(HaClose,a),slope)<0,colorRed,colorBlue);
Color=IIf(Haclose>MA(HaClose,a),colorBlue, colorRed);
PlotOHLC( HaOpen, HaOpen, HaClose, HaClose, "" + Name(), color, styleCandle);

Buy=Cover= Cross(Haclose,MA(HaClose,a));
Sell=Short= Cross(MA(HaClose,a),Haclose);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

_SECTION_END(); 

Sir, Did you find code you required?

Got one solution

Oncandle=ParamList("Trade","OnCandle Completion|Immediate",0);

 if(Oncandle=="OnCandle Completion")
{
   
Buy=Ref(Buy,-1 ) ;
Sell=Ref(Sell,-1 ) ;

}

use “exrem”

This is not an nice solution, it will delay more time for entering into trade while doing auto trade hence we need help how to make wait 10 seconds buy and sell signals to confime that the signals are genuine.

Kindly help us…