AFL - help with Buy and Sell Cond

#1
Hi all,

Can some one help me with the following AFL wih the Buy and Sell conditions.

Buy on the bar after trigger bar i.e. buy if the Price is higher than trigger bar which is (C>MA(C,P1) AND C>MA(C,P2)) and sell if the price is lower than the trigger bar which is (C<MA(C,P1) AND C<MA(C,P2)).


SetChartBkColor(ParamColor("Outer panel color ",colorLightGrey));

SetChartOptions(0,chartShowArrows|chartShowDates);
SetPositionSize(2, spsShares);

_SECTION_BEGIN("Price");

_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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
P1 = Param("Period1", 15, 2, 300, 1, 10 );
Plot( MA( C, P1 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
P2 = Param("Period2", 15, 2, 300, 1, 10 );
Plot( MA( C, P2 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

color = IIf(C>MA(C,P1) AND C>MA(C,P2),colorBlue,IIf(C<MA(C,P1) AND C<MA(C,P2),colorRed, colorBlack));
Plot( C, "Close", color, styleNoTitle |styleCandle );

Col=IIf(MA(C,P1)>MA(C,P2),colorLightBlue,colorYellow);
PlotOHLC( 0,MA(C,P1), MA(C,P2), 0, "Cloud", col, styleCloud );

Buy = (C>MA(C,P1) AND C>MA(C,P2));
Short =(C<MA(C,P1) AND C<MA(C,P2));

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBlue, 0,L,Offset=-15);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGold, 0, H, Offset=15);




Thanks
Amruta