//@version=5 strategy("Previous Day High/Low Scalping Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // --- Inputs --- timezoneInput = input.string("Asia/Kolkata", title="Market Timezone") sessionInput = input.string("0915-1145", title="Allowed Trade Window (2.5 Hours)") showLevels = input.bool(true, title="Show PDH/PDL Lines") // --- Calculations --- // Fetch Daily High/Low of previous day pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_off) pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_off) // Session check inSession = not na(time(timeframe.period, sessionInput + ":23456", timezoneInput)) // 15-minute Breakout tracking breakout15mUp = request.security(syminfo.tickerid, "15", close[1] > pdh[1], lookahead=barmerge.lookahead_off) breakout15mDown = request.security(syminfo.tickerid, "15", close[1] < pdl[1], lookahead=barmerge.lookahead_off) // Candlestick Pattern Detections (to run on 5m timeframe) bodySize = math.abs(close - open) candleRange = high - low lowerShadow = math.min(open, close) - low upperShadow = high - math.max(open, close) isHammer = (candleRange > 0) and (lowerShadow > candleRange * 0.6) and (upperShadow < candleRange * 0.15) isShootingStar = (candleRange > 0) and (upperShadow > candleRange * 0.6) and (lowerShadow < candleRange * 0.15) isBullishEngulfing = (close[1] < open[1]) and (close > open) and (close >= open[1]) and (open <= close[1]) isBearishEngulfing = (close[1] > open[1]) and (close < open) and (close <= open[1]) and (open >= close[1]) // Pullback / Retest check on 5m chart pullbackToPDH = (low <= pdh) and (close >= pdh * 0.995) pullbackToPDL = (high >= pdl) and (close <= pdl * 1.005) // --- Execution State Management --- var float entrySL = na var float entryTP1 = na var float entryTP2 = na var bool tp1Hit = false if (strategy.position_size == 0) tp1Hit := false entrySL := na entryTP1 := na entryTP2 := na // --- Entry Rules --- longCondition = inSession and breakout15mUp and pullbackToPDH and (isHammer or isBullishEngulfing) shortCondition = inSession and breakout15mDown and pullbackToPDL and (isShootingStar or isBearishEngulfing) if (longCondition and strategy.position_size == 0) risk = close - low if risk > 0 entrySL := low entryTP1 := close + risk * 2 entryTP2 := close + risk * 3 strategy.entry("Long", strategy.long) if (shortCondition and strategy.position_size == 0) risk = high - close if risk > 0 entrySL := high entryTP1 := close - risk * 2 entryTP2 := close - risk * 3 strategy.entry("Short", strategy.short) // --- Active Trade Management (Trailing & Take Profits) --- if (strategy.position_size > 0) if not tp1Hit and high >= entryTP1 tp1Hit := true entrySL := strategy.position_avg_price // Move Stop Loss to Entry (Breakeven) if tp1Hit strategy.exit("TP2/SL_Trail", "Long", qty_percent=100, limit=entryTP2, stop=entrySL) else strategy.exit("TP1", "Long", qty_percent=50, limit=entryTP1, stop=entrySL) strategy.exit("TP2", "Long", qty_percent=50, limit=entryTP2, stop=entrySL) if (strategy.position_size < 0) if not tp1Hit and low <= entryTP1 tp1Hit := true entrySL := strategy.position_avg_price // Move Stop Loss to Entry (Breakeven) if tp1Hit strategy.exit("TP2/SL_Trail", "Short", qty_percent=100, limit=entryTP2, stop=entrySL) else strategy.exit("TP1", "Short", qty_percent=50, limit=entryTP1, stop=entrySL) strategy.exit("TP2", "Short", qty_percent=50, limit=entryTP2, stop=entrySL) // --- Plotting --- plot(showLevels ? pdh : na, color=color.green, linewidth=2, title="Previous Day High") plot(showLevels ? pdl : na, color=color.red, linewidth=2, title="Previous Day Low")