//@version=5 strategy("Lewis Kelly SMC Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // --- INPUTS --- i_length = input.int(5, title="Swing Lookback Length", group="Structure Settings") i_rr = input.float(3.0, title="Risk-to-Reward Ratio", group="Risk Management") // --- SWING STRUCTURE MAPPING --- // Using pivot highs and lows to track external swing structure float p_high = ta.pivothigh(high, i_length, i_length) float p_low = ta.pivotlow(low, i_length, i_length) var float swing_high = na var float swing_low = na var bool is_bullish = true if (not na(p_high)) swing_high := p_high if (not na(p_low)) swing_low := p_low // Trend State Switch (Change of Character / BOS tracking) if (not na(swing_high) and close > swing_high) is_bullish := true else if (not na(swing_low) and close < swing_low) is_bullish := false // Plot Key Levels plot(swing_high, title="Swing High", color=color.red, style=plot.style_linebr) plot(swing_low, title="Swing Low", color=color.green, style=plot.style_linebr) // --- ENTRY EXECUTION --- bool can_trade = strategy.position_size == 0 // Long Entry when swing structure is bullish and price pulls back to swing low if (can_trade and is_bullish and not na(swing_low)) float entry_price = close float stop_loss = swing_low - (ta.atr(14) * 0.1) // Small buffer below swing low float risk = entry_price - stop_loss float target = entry_price + (risk * i_rr) if (risk > 0) strategy.entry("SMC Long", strategy.long) strategy.exit("Exit Long", "SMC Long", stop=stop_loss, limit=target) // Short Entry when swing structure is bearish and price reaches supply/swing high if (can_trade and not is_bullish and not na(swing_high)) float entry_price = close float stop_loss = swing_high + (ta.atr(14) * 0.1) // Small buffer above swing high float risk = stop_loss - entry_price float target = entry_price - (risk * i_rr) if (risk > 0) strategy.entry("SMC Short", strategy.short) strategy.exit("Exit Short", "SMC Short", stop=stop_loss, limit=target)