NF Swing Trading using Fractal AFL

oldtrader

Well-Known Member
hello OT..

i was thinking for past few days.. dont know much about optimization.. there is this 315 AFL which im posting here.. if we merge both, which has buy and sell signals embedded in it too.. TAKING ITS buy signal only if price above fractal.. and sell if below.. Point is we will reduce much loss / loss in profit (points already made) when it gives sell signal..,and we stay SOH ie leave our position and enter back when it shows buy again.., if the price lies above fractal level and vice versa..

tell me if u did not understand.. and i'm not sure if this can be optimized..

here s the code
Hi aaru,

Pls place the AFL code inside scroll window to facilitate ease in reading.
Pls select the entire AFL code and click on the "#" tag at the top. This will place the AFL in a scrollable window and will be easy to read.




Regards
 
Last edited:

aaru

Well-Known Member
and well u said for the exit.. i dont think it will be based on either of the two conditions.., as fractal is not as sensitive as 315.. for exit as well as re entry based on 315 itslf as long as price stays above fractal level.. with ths modifications.., if both the levels are closer at EOD thn we may exit.. thus saving us from gaps and re enter both based on 315 if fractals also permitting
 

aaru

Well-Known Member
Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}},{{VALUES}},\n Op - %g \n Hi - %g \n Lo - %g \n Cl - %g", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


SetChartOptions(0,chartShowArrows|chartShowDates);
e1=EMA(C,3);
e2=EMA(C,15);
Plot(e1,"",colorBlue,styleThick);
Plot(e2,"",colorRed,styleThick );

Buy=Cross(e1,e2);
Sell=Cross(e2,e1);

Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
SHtrend=IIf(BarsSince(Buysetup)<BarsSince(Shortset up ),1,0);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Buyt=ValueWhen(Buy,H,1);
Sellt=ValueWhen(Sell,L,1);
Buyt=IIf(SHtrend==1,Buyt,0);
Sellt=IIf(SHtrend==0,Sellt,0);
Buytt=Cross(H,Buyt)AND SHtrend==1;
selltt=Cross(Sellt,L)AND SHtrend==0;
Buytt = ExRem(Buytt, Selltt);
Selltt = ExRem(Selltt, Buytt);

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



Col=IIf(SHtrend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);

ribboncol= IIf( BarsSince(Buysetup)<BarsSince(Shortsetup),colorGre en, colorRed ); //315 Trend
Plot(3, "SH315", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );


Title = EncodeColor(colorWhite)+ "SH 315" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +"\n" +EncodeColor(colorWhite) +"Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+EncodeColor(colorRed)+"Close-"+C+" " +EncodeColor(colorWhite)+ "Vol= "+ WriteVal(V)+EncodeColor(colorLime) +" EMA1 : "+e1+" "+EncodeColor(colorOrange) +" EMA2 : "+e2+" ";SetChartOptions(0,chartShowArrows|chartShowD ates );
e1=EMA(C,3);
e2=EMA(C,15);
Plot(e1,"",colorWhite,styleThick);
Plot(e2,"",colorRed,styleThick );

Buy=Cross(e1,e2);
Sell=Cross(e2,e1);

Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
SHtrend=IIf(BarsSince(Buysetup)<BarsSince(Shortset up ),1,0);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Buyt=ValueWhen(Buy,H,1);
Sellt=ValueWhen(Sell,L,1);
Buyt=IIf(SHtrend==1,Buyt,0);
Sellt=IIf(SHtrend==0,Sellt,0);
Buytt=Cross(H,Buyt)AND SHtrend==1;
selltt=Cross(Sellt,L)AND SHtrend==0;
Buytt = ExRem(Buytt, Selltt);
Selltt = ExRem(Selltt, Buytt);

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



Col=IIf(SHtrend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);

ribboncol= IIf( BarsSince(Buysetup)<BarsSince(Shortsetup),colorGre en, colorRed ); //315 Trend
Plot(3, "SH315", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );


Title = EncodeColor(colorWhite)+ "SH 315" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +"\n" +EncodeColor(colorWhite) +"Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+EncodeColor(colorRed)+"Close-"+C+" " +EncodeColor(colorWhite)+ "Vol= "+ WriteVal(V)+EncodeColor(colorLime) +" EMA1 : "+e1+" "+EncodeColor(colorOrange) +" EMA2 : "+e2+" ";



thanks got it :)
 

oldtrader

Well-Known Member
and well u said for the exit.. i dont think it will be based on either of the two conditions.., as fractal is not as sensitive as 315.. for exit as well as re entry based on 315 itslf as long as price stays above fractal level.. with ths modifications.., if both the levels are closer at EOD thn we may exit.. thus saving us from gaps and re enter both based on 315 if fractals also permitting
The conditions you are stating are good, but it is not easy to put in code, need some help from experts.
 

hmp

Well-Known Member
Dear all
This is crude oil 5 min fractal with parameters suggested by oldtraderji along with ema 315 chart.Fractal chart suggests short position but there are so many whipsaws in 315 that its difficult to decide direction. So this has to be taken into consideration.
Regards
 
Dear OT
Have read all your posts in the thread. Excellent stuff.

Is your afl code on post #36 still the same or have you made any additional changes since. ?

Thanks
 

aaru

Well-Known Member
not sure about crude.. check with ATM nifty and NF too.. 315 keeps u in the trend and gives early entry.. use with 7min TF.. smaller tfs more whipsaws again.. point here is to introduce another set of MA s tht gives us better exit and protects points than taking fractal exit which at times gives up many earned points
 

oldtrader

Well-Known Member
Dear OT
Have read all your posts in the thread. Excellent stuff.

Is your afl code on post #36 still the same or have you made any additional changes since. ?

Thanks
There are no changes till now, Whatever tweaks I have tried so far are not giving anything more than the original one, so I am still using the code in post # 36.
 

Similar threads