//@version=5 strategy("TradingLab 3-Step Strategy [Complete]", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.02) // --- INPUTS --- min_rr = input.float(2.5, title="Minimum Risk-to-Reward Ratio") lookback = input.int(5, title="Structure Lookback Period") stop_buffer = input.float(0.5, title="Stop Loss Buffer (Ticks)") // --- MARKET STRUCTURE & TREND --- // Identifying swing highs and lows var int trend = 0 // 1 = Uptrend, -1 = Downtrend float recent_high = ta.highest(high, lookback) float recent_low = ta.lowest(low, lookback) // Simplified trend state tracking via higher highs/higher lows or lower lows/lower highs bool higher_high = high > ta.highest(high, lookback)[1] bool higher_low = low > ta.lowest(low, lookback)[1] bool lower_low = low < ta.lowest(low, lookback)[1] bool lower_high = high < ta.highest(high, lookback)[1] if (higher_high and higher_low) trend := 1 // Uptrend else if (lower_low and lower_high) trend := -1 // Downtrend // --- SUPPLY & DEMAND ZONE DETECTION --- // Demand Zone: Up candle or consolidation before a strong upward impulsive move // Supply Zone: Down candle or consolidation before a strong downward impulsive move float body_size = math.abs(close - open) float avg_body = ta.sma(body_size, 20) bool is_impulse_up = (close > open) and (body_size > avg_body * 1.5) bool is_impulse_down = (close < open) and (body_size > avg_body * 1.5) var float demand_zone_low = na var float demand_zone_high = na var float supply_zone_low = na var float supply_zone_high = na // Mark Demand Zone (The candle before the bullish impulse) if is_impulse_up and trend == 1 demand_zone_low := low[1] demand_zone_high := high[1] // Mark Supply Zone (The candle before the bearish impulse) if is_impulse_down and trend == -1 supply_zone_low := low[1] supply_zone_high := high[1] // --- ENTRY & RISK MANAGEMENT EXECUTION --- // Long Entry: In an uptrend, price retraces into the Demand Zone bool touch_demand = (low <= demand_zone_high) and (high >= demand_zone_low) if trend == 1 and touch_demand and strategy.position_size == 0 float entry_price = close float stop_loss = demand_zone_low - (stop_buffer * syminfo.mintick) float risk = entry_price - stop_loss float take_profit = entry_price + (risk * min_rr) // Ensure RR requirement is met if risk > 0 strategy.entry("Demand Long", strategy.long) strategy.exit("Long Exit", "Demand Long", stop=stop_loss, limit=take_profit) // Short Entry: In a downtrend, price retraces into the Supply Zone bool touch_supply = (high >= supply_zone_low) and (low <= supply_zone_high) if trend == -1 and touch_supply and strategy.position_size == 0 float entry_price = close float stop_loss = supply_zone_high + (stop_buffer * syminfo.mintick) float risk = stop_loss - entry_price float take_profit = entry_price - (risk * min_rr) if risk > 0 strategy.entry("Supply Short", strategy.short) strategy.exit("Short Exit", "Supply Short", stop=stop_loss, limit=take_profit) // --- PLOTS --- plot(demand_zone_high, color=color.new(color.green, 50), style=plot.style_linebr, title="Demand Zone High") plot(demand_zone_low, color=color.new(color.green, 50), style=plot.style_linebr, title="Demand Zone Low") plot(supply_zone_high, color=color.new(color.red, 50), style=plot.style_linebr, title="Supply Zone High") plot(supply_zone_low, color=color.new(color.red, 50), style=plot.style_linebr, title="Supply Zone Low")