_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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA Xross Sys");
//Optimization parameters for MA
P1 = Optimize("Period 1",Param("Period 1", 20, 2, 300, 1), 10, 300, 10);
P2 = Optimize("Period 2",Param("Period 2", 60, 2, 300, 1), 20, 300, 10);
A=MA(Close,P1); B=MA(Close,P2);
//Plot MAs
Plot(A,"\nMA1",ParamColor("Color1", colorGreen),ParamStyle("Style1") );
Plot(B,"MA2", ParamColor("Color2", colorYellow), ParamStyle("Style2") );
//MA-Cross System for Backtest
Buy = Cross(A,B); Sell = Cross(B,A);
Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy);
Short = Sell; Cover = Buy;
UP = Flip(Buy,Sell); DN = Flip(Sell,Buy);
//Arrows
PlotShapes(Buy+2*Sell, IIf(Buy,colorGreen,colorRed), 0,IIf(Buy,L,H));
//Trade Action on next bar open after MA-Cross
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open; SellPrice = Open;
CoverPrice = Open; ShortPrice = Open;
//Position sizing
SetPositionSize(1,4);
//Stops
ApplyStop(0,2,25); // Stop Loss
ApplyStop(1,2,50); //Profit Stop
//Plots for TGT & Stops
Long = ValueWhen(Ref(Buy,-1),O);
Shrt = ValueWhen(Ref(Sell,-1),O);
Plot(IIf(UP,Long,Shrt),"ENTRY_PRICE",colorLightGrey,styleStaircase|styleNoRescale|styleDashed);
Plot(IIf(UP,Long+50,Null),"\nLong_TGT",colorBlueGrey,styleStaircase|styleNoRescale);
Plot(IIf(UP,Long-25,Null),"Long_SL", colorLime, styleStaircase|styleNoRescale);
Plot(IIf(DN,Shrt-50,Null),"\nShort_TGT",colorRed, styleStaircase|styleNoRescale);
Plot(IIf(DN,Shrt+25,Null),"Short_SL", colorBlue,styleStaircase|styleNoRescale|styleDashed);
/*
Plot(SelectedValue(IIf(UP,Long-25,Null)),"Long_SL",colorRed,styleStaircase|styleNoRescale,0,0,10);
Plot(SelectedValue(IIf(UP,Long+50,Null)),"Long_TGT",colorBlue,styleStaircase|styleNoRescale,0,0,10);
Plot(SelectedValue(IIf(DN,Shrt+25,Null)),"Short_SL",colorBlue,styleStaircase,0,0,10);
Plot(SelectedValue(IIf(DN,Shrt-50,Null)),"Short_TGT",colorRed,styleStaircase,0,0,10);
*/
//exploration
Filter = Buy OR Sell;
_SECTION_END();