AFL Help Required To Delay Buy Sell Signal

#1
Hello Friends,

In below mention afl i required some help with buy and sell signal.

When i wanted to delay buy and sell signal to next candle.

If buy signal comes and next candle crossed the high of that buy candle then only Buy Signal should be considered and for sell vise varsa.

ALF cade is as below.

_SECTION_BEGIN("Price");
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();

// RSI Levels - appplied to Price Chart shows how far
// tomorrow's closing price has to move in order for
// the RSI to cross the 70, 50 & 30 levels.

pd = Param("Periods",200,5,200,1);
pds = 2*pd-1;// (Adjustment for Wilders MA)

aa = Close-Ref(Close,-1);
uu = EMA(Max(0,aa),pds);
dd= EMA((Max(0,0-aa)),pds);

rf = IIf(C>2,1000,10000);

c1 = Param("Upper Level",52,50,90,1);
qq1 =100/(100-c1)-1;
ff1 = qq1*dd-uu;
ff2 = ff1/qq1;
f1 = Max(ff1,ff2);
UL = Close + f1*(pds-1)/2;
UL = IIf(UL>C,floor(UL*rf),ceil(UL*rf))/rf;

c2 = Param("Equilibrium",50,50,50,0);
qq2 =100/(100-c2)-1;// [=1]
ff = dd-uu;
MM = Close + ff*(pds-1)/2;
MM = IIf(MM>C,floor(MM*rf),ceil(MM*rf))/rf;

c3 = Param("Lower Level",48,10,50,1);
qq3 =100/(100-c3)-1;
ff1 = qq3*dd-uu;
ff2 = ff1/qq3;
f3 = Min(ff1,ff2);
LL = Close + f3*(pds-1)/2;
LL = IIf(LL>C,floor(LL*rf),ceil(LL*rf))/rf;

Plot(UL,"",colorRed,1);
Plot(MM,"",colorWhite,32);
Plot(LL,"",colorGreen,1);

Cbr = IIf(UL<C,27,IIf(LL>C,32,IIf(MM>C,11,8)));
PlotOHLC(O,H,L,C,"",cbr,styleCandle);
pema=Param("Per",3,1,10,1);



Buy=Cross(EMA(C,pema),mm);
Sell=Cross(mm,EMA(C,pema));
shape=Buy*shapeUpArrow+Sell*shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, L-2, IIf(Sell,H+2,Null)));


Title = Name() + " - RSI(" + WriteVal(pd,0.0) + ") - Close=" + WriteVal(Close,0.3) + " UL=" + WriteVal(UL,0.4) + " MM=" + WriteVal(MM,0.4) + " LL=" + WriteVal(LL,0.4);_SECTION_BEGIN("Price");
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();
 

mastermind007

Well-Known Member
#2
Correction is in following two lines. Code in Red is to be added at appropriate line.

....
Buy=Ref(Cross(EMA(C,pema),mm),-1);
Sell=Ref(Cross(mm,EMA(C,pema)),,-1);
....
 
#3
Thnx Sir for your time and reply..

But still it has some problem.

It showing sell at very next candle but

But sell should be only come if it brakes Low of that Sell Candle if the next candle doesn't brake the low of that previous candle then sell should not come. when the low is broken even after few candle then only sell should come.


I am sending link where this kind of chart and formula is present.

http://www.marketcalls.in/amibroker/supertrend-high-low-breakout-strategy-amibroker-afl-code.html



Plz Suggest Coding according to this Alf Code.



Thanking you Sir,

Chetan
 
#4
But sell should be only come if it brakes Low of that Sell Candle if the next candle doesn't brake the low of that previous candle then sell should not come. when the low is broken even after few candle then only sell should come.
I too want to add these condition in my AFL.
can any one suggest some code...?
 
#6
_SECTION_BEGIN("Price");
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();

// RSI Levels - appplied to Price Chart shows how far
// tomorrow's closing price has to move in order for
// the RSI to cross the 70, 50 & 30 levels.

pd = Param("Periods",200,5,200,1);
pds = 2*pd-1;// (Adjustment for Wilders MA)

aa = Close-Ref(Close,-1);
uu = EMA(Max(0,aa),pds);
dd= EMA((Max(0,0-aa)),pds);

rf = IIf(C>2,1000,10000);

c1 = Param("Upper Level",52,50,90,1);
qq1 =100/(100-c1)-1;
ff1 = qq1*dd-uu;
ff2 = ff1/qq1;
f1 = Max(ff1,ff2);
UL = Close + f1*(pds-1)/2;
UL = IIf(UL>C,floor(UL*rf),ceil(UL*rf))/rf;

c2 = Param("Equilibrium",50,50,50,0);
qq2 =100/(100-c2)-1;// [=1]
ff = dd-uu;
MM = Close + ff*(pds-1)/2;
MM = IIf(MM>C,floor(MM*rf),ceil(MM*rf))/rf;

c3 = Param("Lower Level",48,10,50,1);
qq3 =100/(100-c3)-1;
ff1 = qq3*dd-uu;
ff2 = ff1/qq3;
f3 = Min(ff1,ff2);
LL = Close + f3*(pds-1)/2;
LL = IIf(LL>C,floor(LL*rf),ceil(LL*rf))/rf;

Plot(UL,"",colorRed,1);
Plot(MM,"",colorWhite,32);
Plot(LL,"",colorGreen,1);

Cbr = IIf(UL<C,27,IIf(LL>C,32,IIf(MM>C,11,8)));
PlotOHLC(O,H,L,C,"",cbr,styleCandle);
pema=Param("Per",3,1,10,1);



Buy=Cross(EMA(C,pema),mm)AND Cross(High,Ref(H,-1));
Sell=Cross(mm,EMA(C,pema))AND Cross(Ref(L,-1),Low);
shape=Buy*shapeUpArrow+Sell*shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, L-2, IIf(Sell,H+2,Null)));


Title = Name() + " - RSI(" + WriteVal(pd,0.0) + ") - Close=" + WriteVal(Close,0.3) + " UL=" + WriteVal(UL,0.4) + " MM=" + WriteVal(MM,0.4) + " LL=" + WriteVal(LL,0.4);_SECTION_BEGIN("Price");
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();
 

Similar threads