_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("LODU BACK TEST");
w = Optimize("PERIOD 1",Param("PERIOD 1",50,5,50,5),10,50,10);
x = Optimize("PERIOD 2",Param("PERIOD 2",40,5,50,5),10,50,10);
y = Optimize("MAType 1",Param("MAType 1",4,1,8,1),1,8,1);
z = Optimize("MAType 2",Param("MAType 2",3,1,8,1),1,8,1);
r = Optimize("Rule Type",Param("Rule Type",7,1,15,1),1,15,1);
m=0; if (y==1) m = MA(C,w);
else if (y==2) m = EMA(C,w);
else if (y==3) m = DEMA(C,w);
else if (y==4) m = TEMA(C,w);
else if (y==5) m = WMA(C,w);
else if (y==6) m = HMA(C,w);
else if (y==7) m = Wilders(C,w);
else if (y==8) m = LinearReg(C,w);
e=0; if (z==1) e = MA(m,x);
else if (z==2) e = EMA(m,x);
else if (z==3) e = DEMA(m,x);
else if (z==4) e = TEMA(m,x);
else if (z==5) e = WMA(m,x);
else if (z==6) e = HMA(m,x);
else if (z==7) e = Wilders(m,x);
else if (z==8) e = LinearReg(m,x);
Plot(m," MA 1",IIf(m > Ref(m,-1),colorBlue,colorRed),styleThick);
Plot(e," MA 2",IIf(e > Ref(e,-1),colorDarkGreen,colorYellow),styleThick);
// using only price & m
if (r==1) {UP = C > m; DN = C < m;}
else if (r==2) {UP = m > Ref(m,-1); DN = m < Ref(m,-1);}
else if (r==3) {UP = C > m AND m > Ref(m,-1); DN = C < m AND m < Ref(m,-1);}
else if (r==4) {UP = H > m AND m > Ref(m,-1); DN = L < m AND m < Ref(m,-1);}
else if (r==5) {UP = L > m; DN = H < m; }
else if (r==6) {UP = L > m AND m > Ref(m,-1); DN = H < m AND m < Ref(m,-1);}
// using only price & e
else if (r==7) {UP = C > e; DN = C < e;}
else if (r==8) {UP = e > Ref(e,-1); DN = e < Ref(e,-1);}
else if (r==9) {UP = C > e AND e > Ref(e,-1); DN = C < e AND e < Ref(e,-1);}
else if (r==10) {UP = H > e AND e > Ref(e,-1); DN = L < e AND m < Ref(e,-1);}
else if (r==11) {UP = L > e; DN = H < e; }
else if (r==12) {UP = L > e AND e > Ref(e,-1); DN = H < e AND m < Ref(e,-1);}
// using all: price, m & e
else if (r==13) {UP = C > m AND m > e; DN = C < m AND m < e;}
else if (r==14) {UP = m > Ref(m,-1) AND e > Ref(e,-1); DN = m < Ref(m,-1) AND e < Ref(e,-1);}
else if (r==15) {UP = C > m AND m > e AND m > Ref(m,-1) AND e > Ref(e,-1);
DN = C < m AND m < e AND m < Ref(m,-1) AND e < Ref(e,-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();