I have made the afl.
I have made modifications for filter a constant value of 5 and added brokerage points and profit loss value of 50 instead of 10 as I was testing for BNF.
But it has some error, which I could not solve so far. I am giving afl below. If some one can rectify it, I will be thankful.
_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", IIf(C>O,colorGreen,colorRed), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Periods = Param("Periods", 110, 2, 300, 1, 10 );
Plot( EMA( C, Periods ),"EMA"+Periods, ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("Trade");
brokeragePoints=5;
tradeFilter=5;
stopSize=50;
profitSize=stopSize+brokeragePoints;
Cc=CCI(14);
em=EMA(C,110);
t=TimeNum();
Buy=0;
Sell=0;
Short=0;
Cover=0;
BP=0;
SP=0;
lng=0;
shrt=0;
for( i = 1; i < BarCount; i++ )
{
if( lng ==0 AND CC[i-1] > 100 AND C[i-1] > em[i-1] AND H >= (H[i-1]+tradeFilter) AND t > 091500 AND t < 151500 )
{
Buy=1;
lng=1;
BP= H[i-1]+tradeFilter;
}
else
{
Buy[ i ] = 0; // remove excess buy signals
lng = 0;
}
if( lng == 1 AND Low[ i ] <= BP- stopSize)
{
Sell[ i ] = 1;
SellPrice[ i ] = BP- stopSize;
lng = 0;
Bp=0;
}
if( lng == 1 AND High[ i ] >= BP+stopSize+ brokeragePoints )
{
Sell[ i ] = 1;
SellPrice[ i ] = BP+ stopSize+ brokeragePoints ;
lng = 0;
Bp=0;
}
if(lng ==1 AND t > 152500)
{
Sell[ i ] = 1;
SellPrice[ i ] = C;
lng = 0;
BP=0;
}
if( shrt ==0 AND Cc[i-1] < -100 AND C[i-1] < em[i-1] AND L <= (L[i-1]-tradeFilter) AND t > 091500 AND t < 151500 )
{
Short=1;
shrt=1;
SP= L[i-1]-tradeFilter;
}
else
{
Short[ i ] = 0; // remove excess buy signals
shrt = 0;
}
if( shrt == 1 AND High[ i ] >= SP+ stopSize)
{
Cover[ i ] = 1;
CoverPrice[ i ] = SP+stopSize;
shrt = 0;
SP=0;
}
if( shrt == 1 AND Low[ i ] <= SP-stopSize- brokeragePoints )
{
Cover[ i ] = 1;
CoverPrice[ i ] = SP-stopSize-brokeragePoints ;
shrt = 0;
SP=0;
}
if(shrt ==1 AND t > 152500)
{
Cover[ i ] = 1;
CoverPrice[ i ] = C;
shrt = 0;
SP=0;
}
}
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,High);
PlotShapes(Short*shapeDownArrow,colorRed,0,High);
PlotShapes(Cover*shapeHollowUpArrow,colorGreen,0,Low);
_SECTION_END();