// Written by: Abhishek Gupta
RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
PointValue = 500;
SetPositionSize(4,spsShares);
SetBarsRequired(50);
_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:25");
CloseTime = ParamTime("Closing Time", "15:20");
Lev = Param("Max diff O-HL", 0.01, 0, 1, 0.01);
Lev1 = Lev/100;
GapFix = Param("Minimum stop loss", 0.05, 0, 1, 0.05);
GapFix1 = GapFix/100;
HighY = TimeFrameGetPrice("High", inDaily, -1);
LowY = TimeFrameGetPrice("Low", inDaily, -1);
OpenD = TimeFrameGetPrice("Open", inDaily);
LowD = LowestSince(NewDay, Low);
HighD = 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));
Plot((OpenD*(1-Lev1)), "Open variant", colorPink, styleDashed);
Plot((OpenD*(1+Lev1)), "Open variant", colorPink, 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*(1-Lev1))<=LowD AND Cross(High, HighY);
Sell = TimeNum()>CloseTime OR Cross(OpenD, Close);
Short = Conds AND (OpenD*(1+Lev1))>=HighD AND Cross(LowY, Low);
Cover = TimeNum()>CloseTime OR Cross(Close, 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, IIf(Cross(High, OpenD), openD, Close));
SellPrice = ValueWhen(Sell, IIf(Cross(OpenD, Low), OpenD, Close) );
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();