I can Create AFL but Need Strategy

johnnypareek

Well-Known Member
#93
Johnybhai...what would be the tgt in this case and how u r handling reentry?
Okay Here it is.

HTML:
/*-Indicators: EMA9 and EMA26 and DMI (Directional Movement Indicator with ADX)

Conditions:

GO LONG WHEN:
- EMA9 has crossed over EMA26
- DI+ >= 25
- ADX >= should be 20 to 35
- ADX is in between DI+ and DI-

EXIT LONG WHEN:
- EMA26 has crossed EMA9 AND
- DI- is higher than DI+
Also Reentering position also need

GO SHORT WHEN:
- EMA26 has crossed EMA9
- DI- >= 25
- ADX >= should be 20 to 35
- ADX is in between DI- and DI+

EXIT SHORT WHEN:
- EMA9 has crossed EMA26 AND
- DI+ is higher than DI-
Reentering position also need

WHAT TO IGNORE:
- While in Long Position: DI+ and DI- Cross-overs while the EMA9 is still on top of EMA26
- While in Short Position: DI+ and DI- Cross-overs while the EMA26 is still on top of EMA9

Buy, Sell arrow need and different symbols need for exit positions, if possible add message board.

*/

_SECTION_BEGIN("Price");

GraphXSpace=5;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
AvgFast=EMA( Close, 9 );
AvgSlow=EMA( Close, 26 );

myPDI=PDI (14); //Plus Directional Movement Indicator

myMDI=MDI (14); //Minus Directional Movement Indicator

myADX=ADX (14);

Plot(AvgFast,"AvgFast",colorBlack, styleLine|styleDashed | styleThick);
Plot(AvgSlow,"AvgFast",colorGreen, styleLine|styleDashed | styleThick);
Plot(myPDI,"myPDI",colorBlue, styleLine|styleLine|styleOwnScale);
Plot(myMDI,"myMDI",colorRed, styleLine|styleLine|styleOwnScale);
Plot(myADX,"myADX",colorBlue, styleLine | styleThick|styleOwnScale);


//entry Criteria Long
//CrLo1=Cross( AvgFast, AvgSlow); //EMA9 has crossed over EMA26

CrLo1= AvgFast> AvgSlow; //EMA9 has crossed over EMA26
CrLo2=myPDI >= 25; //DI+ >= 25
CrLo3=myADX >= 20 AND myADX <=35; //ADX >= should be 20 to 35
CrLo4=myADX > myMDI AND myADX < myPDI; //ADX is in between DI+ and DI-

//ShortCriteria Long
//CrLo5=Cross( AvgSlow, AvgFast); //EMA26 has crossed over EMA9

CrLo5= AvgSlow> AvgFast; //EMA26 has crossed over EMA9
CrLo6=myMDI >= 25; //DI- >= 25
CrLo7=myADX >= 20 AND myADX <=35; //ADX >= should be 20 to 35
CrLo8=myADX > myPDI AND myADX < myMDI; //ADX is in between DI+ and DI-



Buy=CrLo1 AND CrLo2 AND CrLo3 AND CrLo4;
Sell=AvgSlow>AvgFast AND myMDI>myPDI;
Short=CrLo5 AND CrLo6 AND CrLo7 AND CrLo8;
Cover=AvgSlow<AvgFast AND myMDI<myPDI;


Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(Buy * shapeUpTriangle,colorGreen, 0,L, Offset=-10); 
PlotShapes(Short * shapeDownTriangle,colorRed, 0,H, Offset=-10);
PlotShapes(Cover * shapeHollowUpArrow,colorGreen, 0,L, Offset=-10); 
PlotShapes(Sell * shapeHollowDownArrow,colorRed, 0,H, Offset=-10);
 
#95
Hi johnny
Nice to see you picked it up!
I played around a bit with the parameters. But I can't see the potential of these criteria. It's buying too high, and selling too low.

Im working on criteria to archive better entry & exit positions....later more

:thumb:
 
Last edited:

johnnypareek

Well-Known Member
#96
Hi johnny
Nice to see you picked it up!
I played around a bit with the parameters. But I can't see the potential of these criteria. It's buying too high, and selling too low.

Im working on criteria to archive better entry & exit positions....later more

:thumb:
That is what I wrote in previous post. Trying to tweak it
 
#97
Hi johnny bhai
Thank you for the nice coding -its a help for us guys.

seems you were busy & an oversight occurs. sorry to point this out.

Plot(AvgFast,"AvgFast",colorBlack, styleLine|styleDashed | styleThick);
Plot(AvgSlow,"AvgFast",colorGreen, styleLine|styleDashed | styleThick);
The second line to read as

Plot(AvgSlow,"AvgSlow",colorGreen, styleLine|styleDashed | styleThick);


In fact I do prefer blue and red color and thick line for fast & slow so thy become readily visible among other lines.

best regards-gratefully for your service to this forum
ford
 
#98
Thank you sir for the hard work, Iam looking forward to new ideas !

Here's maybe useful code to display the difference.
You can enable/disable it in parameters
I just don't know how to scale it in the chart properly

_SECTION_BEGIN("Histogram");

BS = ParamToggle("smooth","No|Yes",1);
BN = ParamToggle("normal","No|Yes",1);

if (BS) Plot( AvgFast, " AvgFast", IIf( AvgFast>=Ref(AvgFast,-1), colorBlue, colorBlue | styleOwnScale));
if (BN) Plot( AvgSlow, " AvgSlow", IIf( AvgSlow>=Ref(AvgSlow,-1), colorRed , colorRed | styleOwnScale ));

HistInd=AvgFast- AvgSlow;

if (BS AND BN) Plot(HistInd, _DEFAULT_NAME(),
IIf(HistInd>=0, ParamColor("Up Color", colorDarkGreen), ParamColor("Down Color", colorRed)),
ParamStyle( "Style", styleHistogram | styleThick, maskHistogram ));
if (BS AND BN) Plot(0,"",colorBlack, styleLine|styleDashed | styleThick);

_SECTION_END();
 
Last edited:

Bewinner

Well-Known Member
#99
Hi johnny
Nice to see you picked it up!
I played around a bit with the parameters. But I can't see the potential of these criteria. It's buying too high, and selling too low.

Im working on criteria to archive better entry & exit positions....later more

:thumb:
Yes I too observed that and found the same
 
The approach to do this in AFL would be be use Plot function to plot 30 minute candles using normal color but use white (same as background) color for places where you want hourly candle. Then using GFX and Time management functions compress the remaining candles, redraw remaining candles on same layer. It is complicated to get it right.
 
Last edited:

Similar threads