//@version=5 strategy("SLC Strategy (Structure, Level, Confirmation)", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // --- Inputs --- htf_res = input.timeframe("240", "HTF Structure Timeframe (S)") atr_len = input.int(14, "ATR Length for S&D Zones") mult = input.float(1.5, "ATR Multiplier for Aggressive Move") stoch_k = input.int(14, "Stochastic %K Length (C)") stoch_d = input.int(3, "Stochastic %D Smoothing") stoch_smooth = input.int(3, "Stochastic %K Smoothing") stoch_upper = input.int(80, "Stochastic Upper Level") stoch_lower = input.int(20, "Stochastic Lower Level") rr_ratio = input.float(2.0, "Risk-to-Reward Ratio") // --- Step 1: Structure (S) on HTF --- // Use lookahead=barmerge.lookahead_off to prevent historical backtest cheating htf_close = request.security(syminfo.tickerid, htf_res, close[1], barmerge.gaps_off, barmerge.lookahead_off) htf_ema = request.security(syminfo.tickerid, htf_res, ta.ema(close, 50)[1], barmerge.gaps_off, barmerge.lookahead_off) is_bullish_htf = htf_close > htf_ema is_bearish_htf = htf_close < htf_ema // --- Step 2: Level (L) - Supply & Demand on LTF --- atr = ta.atr(atr_len) body = math.abs(close - open) is_aggressive_up = (close > open) and (body > atr * mult) is_aggressive_down = (close < open) and (body > atr * mult) var float supply_high = na var float supply_low = na var float demand_high = na var float demand_low = na // Supply Level: Last bullish candle before aggressive move down if is_aggressive_down and (close[1] > open[1]) supply_high := high[1] supply_low := low[1] // Demand Level: Last bearish candle before aggressive move up if is_aggressive_up and (close[1] < open[1]) demand_high := high[1] demand_low := low[1] // Check if price is within levels in_supply = (high >= supply_low) and (low <= supply_high) in_demand = (low <= demand_high) and (high >= demand_low) // --- Step 3: Confirmation (C) - Stochastic --- stoch_raw = ta.stoch(close, high, low, stoch_k) stoch_k_val = ta.sma(stoch_raw, stoch_smooth) stoch_d_val = ta.sma(stoch_k_val, stoch_d) stoch_cross_down = ta.crossunder(stoch_k_val, stoch_upper) stoch_cross_up = ta.crossover(stoch_k_val, stoch_lower) // --- Strategy Rules and Order Execution --- long_cond = is_bullish_htf and in_demand and stoch_cross_up and strategy.position_size == 0 short_cond = is_bearish_htf and in_supply and stoch_cross_down and strategy.position_size == 0 var float entry_price = na var float stop_loss = na var float take_profit = na if long_cond entry_price := close stop_loss := demand_low take_profit := entry_price + (entry_price - stop_loss) * rr_ratio strategy.entry("Long", strategy.long) strategy.exit("Exit Long", "Long", stop=stop_loss, limit=take_profit) if short_cond entry_price := close stop_loss := supply_high take_profit := entry_price - (stop_loss - entry_price) * rr_ratio strategy.entry("Short", strategy.short) strategy.exit("Exit Short", "Short", stop=stop_loss, limit=take_profit) // Reset state values once positions are hit if strategy.position_size == 0 entry_price := na stop_loss := na take_profit := na // --- Visualizing Supply & Demand Zones --- plot(supply_high, "Supply High", color=color.red, linewidth=1) plot(supply_low, "Supply Low", color=color.red, linewidth=1) plot(demand_high, "Demand High", color=color.green, linewidth=1) plot(demand_low, "Demand Low", color=color.green, linewidth=1)