_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("BAKWAS BACK TEST");
y = Optimize("PERIOD",Param("PERIOD",90,10,200,10),10,200,10);
z = Optimize("MAType",Param("MAType",2,1,8,1),1,8,1);
x = Optimize("TRules",Param("TRules",1,1,3,1),1,3,1);
m=0; if (z==1) m = MA(C,y);
else if (z==2) m = EMA(C,y);
else if (z==3) m = DEMA(C,y);
else if (z==4) m = TEMA(C,y);
else if (z==5) m = WMA(C,y);
else if (z==6) m = HMA(C,y);
else if (z==7) m = Wilders(C,y);
else if (z==8) m = LinearReg(C,y);
Plot(m," MA",IIf(m < Ref(m,-1),colorBlue,colorRed),styleThick);
if (x==1) {UP = C > m; DN = C < m;}
else if (x==2) {UP = m > Ref(m,-1); DN = m < Ref(m,-1);}
else if (x==3) {UP = C > m AND m > Ref(m,-1); DN = C < m AND m < Ref(m,-1);}
Buy = UP AND NOT (DN);
Sell = DN AND NOT (UP);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell; Cover = Buy;
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H));
SetPositionSize(1,4);
_SECTION_END();