_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();
_SECTION_BEGIN("Trading signals");
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);
Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);
StartTime = ParamTime("Start time", "09:15");
CloseTime = ParamTime("Closing Time", "15:20");
GapFix = Param("Minimum stop loss", 0.015, 0, 1, 0.05);
GapFix1 = GapFix/100;
HighY = TimeFrameGetPrice("High", inDaily, -1);
LowY = TimeFrameGetPrice("Low", inDaily, -1);
OpenD = TimeFrameGetPrice("Open", inDaily);
//LowD = TimeFrameGetPrice("Low", inDaily);
//HighD = TimeFrameGetPrice("High", inDaily);
xFilter = BarsSince(Cross(High, HighY))>BarsSince(NewDay) OR BarsSince(Cross(LowY, Low))>BarsSince(NewDay);
LowD = ValueWhen(xFilter, LowestSince(NewDay, Low));
HighD = ValueWhen(xFilter, HighestSince(NewDay, High));
Plot(HighY, "Y's H ", ParamColor("Y's High Color", colorYellow), ParamStyle("Y's High Style", styleDashed));
Plot(LowY, "Y's L ", ParamColor("Y's Low Color", colorYellow), ParamStyle("Y's Low Style", styleDashed));
Plot(OpenD, "Day's O ", ParamColor("Day's Open Color", colorRed), ParamStyle("Day's Open Style", styleDashed));
Plot(LowD, "Day's L ", ParamColor("Day's Low Color", colorGreen), ParamStyle("Day's Low Style", styleDashed));
Plot(HighD, "Day's H ", ParamColor("Day's High Color", colorGreen), ParamStyle("Day's High Style", styleDashed));
// Filter time, low and high conditions
Conds = TimeNum()>StartTime AND TimeNum()<CloseTime AND (OpenD*(1+GapFix1))<HighY AND (OpenD*(1-GapFix1))>LowY;
Buy = Conds AND OpenD==LowD AND Cross(High, HighY);
Sell = Cross(TimeNum(), CloseTime) OR Cross(OpenD, Low);
Short = Conds AND OpenD==HighD AND Cross(LowY, Low);
Cover = Cross(TimeNum(), CloseTime) OR Cross(High, OpenD);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
BuyPrice = ValueWhen(Buy, HighY);
ShortPrice = ValueWhen(Short, LowY);
CoverPrice = ValueWhen(Cover, OpenD);
SellPrice = ValueWhen(Sell, OpenD);
dist = 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
if (Cover[i]) {
PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
} else if (Sell[i]) {
PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
}
if(Buy[i]) {
PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
} else if( Short[i]) {
PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
}
}
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);
printf("\nSignal came " + IIf(BarsSince(Short)>BarsSince(Buy), BarsSince(Buy), BarsSince(Short)) + " bars ago");
WriteIf(BarsSince(Short)>BarsSince(Buy), "\nBuy@ " + BuyPrice, "\nShort@ " + ShortPrice);
printf("\nPossiblities ");
printf("\nMax Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (HighD-BuyPrice), (ShortPrice-LowD)));
printf("\nMin Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (OpenD-BuyPrice), (ShortPrice-OpenD)));
// Write Messages
printf("\n\nLet the profit run.");
printf("\nClose a call only when trailing SL hits");
_SECTION_END();