RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 25;
SetPositionSize(4,spsShares);
SetBarsRequired(5*12);
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
expand = expandLast;
x5 = Close - Open;
TimeFrameSet(in15Minute);
x15 = Close - Open;
x15e = TimeFrameExpand(x15, in15Minute, expand);
TimeFrameRestore();
TimeFrameSet(in15Minute*2);
x30 = Close - Open;
x30e = TimeFrameExpand(x30, in15Minute*2, expand);
TimeFrameRestore();
TimeFrameSet(inHourly);
x60 = Close - Open;
x60e = TimeFrameExpand(x60, inHourly, expand);
TimeFrameRestore();
_SECTION_BEGIN("Trading signals");
tsl = Param("bars", 2, 1, 10, 1);
tsl = Optimize("bars", tsl, 1, 10, 1);
Buy = x5>0 AND x15e>0 AND x30e>0 AND x60e>0;
LongSL = ValueWhen(Buy, LLV(Low, tsl));
Sell = Cross(LongSL, Close);
Short = x5<0 AND x15e<0 AND x30e<0 AND x60e<0;
ShortSL= ValueWhen(Short, HHV(High, tsl));
Cover = Cross(Close, ShortSL);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
BuyPrice = ValueWhen(Buy, Close);
SellPrice = ValueWhen(Sell, Close);
ShortPrice = ValueWhen(Short, Close);
CoverPrice = ValueWhen(Cover, Close);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);
dist = 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
if (Cover) {
PlotText( "\nCover short: " + CoverPrice, i+1.5, L[ i ]-dist-3, colorLime);
PlotText( "\n\nProfit: " + (ShortPrice-CoverPrice), i+1.5, L[ i ]-dist-3, colorLime);
} else if (Sell) {
PlotText( "\nSell bought: " + SellPrice, i+1.5, H[ i ]+dist+5, colorOrange);
PlotText( "\n\nProfit: " + (SellPrice-BuyPrice), i+1.5, H[ i ]+dist+5, colorOrange);
}
if(Buy) {
PlotText( "Buy: " + BuyPrice, i+1.5, L[ i ]-dist-3, colorLime);
sig = "Buy";
} else if( Short) {
PlotText( "Short: " + ShortPrice, i+1.5, H[ i ]+dist+5, colorOrange);
sig = "Short";
}
}
_SECTION_END();