//@version=5 strategy("Major Swing Structure Day Trading Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) // Inputs htfResolution = input.timeframe("60", "Higher Timeframe (HTF) for Trend") htfEmaPeriod = input.int(50, "HTF Trend EMA Period", minval=1) ltfEmaPeriod = input.int(20, "LTF Pullback EMA Period", minval=1) pivotLegs = input.int(5, "Swing Structure Pivot Strength", minval=1) rrRatio = input.float(2.4, "Risk to Reward Ratio", minval=1.0, step=0.1) // LTF Pullback Indicator ltfEma = ta.ema(close, ltfEmaPeriod) plot(ltfEma, title="LTF Pullback EMA (20)", color=color.blue, linewidth=2) // HTF Structure & Trend Filter htfClose = request.security(syminfo.tickerid, htfResolution, close, lookahead=barmerge.lookahead_off) htfEma = request.security(syminfo.tickerid, htfResolution, ta.ema(close, htfEmaPeriod), lookahead=barmerge.lookahead_off) htfIsBullish = htfClose > htfEma htfIsBearish = htfClose < htfEma // LTF Major/Minor Swing Pivots pivotHigh = ta.pivothigh(high, pivotLegs, pivotLegs) pivotLow = ta.pivotlow(low, pivotLegs, pivotLegs) var float recentSwingLow = na var float recentSwingHigh = na if not na(pivotLow) recentSwingLow := pivotLow if not na(pivotHigh) recentSwingHigh := pivotHigh plot(recentSwingLow, title="Recent Swing Low", color=color.green, style=plot.style_circles, linewidth=2) plot(recentSwingHigh, title="Recent Swing High", color=color.red, style=plot.style_circles, linewidth=2) // Entry Conditions // Long: HTF Trend Bullish + LTF Price pulled back below LTF EMA and now closed back above LTF EMA longSetup = htfIsBullish and close[1] <= ltfEma[1] and close > ltfEma shortSetup = htfIsBearish and close[1] >= ltfEma[1] and close < ltfEma if (longSetup and strategy.position_size == 0) sl = not na(recentSwingLow) and recentSwingLow < close ? recentSwingLow : ta.lowest(low, 10) risk = close - sl if risk > 0 tp = close + (risk * rrRatio) strategy.entry("Long Continuation", strategy.long) strategy.exit("Exit Long", "Long Continuation", stop=sl, limit=tp) if (shortSetup and strategy.position_size == 0) sl = not na(recentSwingHigh) and recentSwingHigh > close ? recentSwingHigh : ta.highest(high, 10) risk = sl - close if risk > 0 tp = close - (risk * rrRatio) strategy.entry("Short Continuation", strategy.short) strategy.exit("Exit Short", "Short Continuation", stop=sl, limit=tp)