Thursday, June 12, 2014

Learn AFL Code : Display Buy and Sell price in price chart using AFL


_SECTION_BEGIN("Debarghya: AFL Coding");

// Simple logic to plot your EMA. You use any EMA value
em3=EMA(C,3);
em13=EMA(C,13);
Plot( em3, "EMA(3)", colorRed );
Plot( em13, "EMA(13)", colorGreen );

PlotOHLC( Open,High,Low,Close, "Price", colorRed, styleCandle);
PlotOHLC( em3,em3,em13,em13, "", IIf( em3 > em13, colorGreen, colorRed ), styleCloud | styleClipMinMax );

Buy=Cross( em3, em13 );
Sell= Cross( em13,em3 );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
dist = 1.7*ATR(10);

PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorGreen,colorYellow );
if( Sell[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist[i], colorRed, colorYellow );
}
_SECTION_END();

I am using
PlotText( ''text'', x, y, color, bkcolor = colorDefault )
to display entry and exit level.

Debarghya Mukherjee
Mobile: (+91)-9038787021
Email: debarghya_mkr@yahoo.com

No comments:

Post a Comment