//@version=5 strategy("Pure Price Action Supply and Demand Strategy - JeaFx", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=2, commission_type=strategy.commission.percent, commission_value=0.03) // --- Inputs --- pivot_length = input.int(5, "Pivot Lookback Length", minval=1, tooltip="Bars required to identify swing highs and lows") rr_ratio = input.float(2.5, "Risk to Reward Ratio", minval=1.0, step=0.1, tooltip="Minimum R:R ratio per trade") use_confirmation = input.bool(false, "Require Low Timeframe Structure Confirmation", tooltip="Wait for secondary break before entering") // --- Swing Highs and Lows --- ph = ta.pivothigh(pivot_length, pivot_length) pl = ta.pivotlow(pivot_length, pivot_length) var float last_swing_high = na var float last_swing_low = na var int market_structure = 0 // 1 = Uptrend, -1 = Downtrend if not na(ph) last_swing_high := ph if not na(pl) last_swing_low := pl // --- Supply & Demand Zones --- var float demand_top = na var float demand_bot = na var bool demand_active = false var float supply_top = na var float supply_bot = na var bool supply_active = false // --- Market Structure Break (BOS) Logic --- bullish_bos = not na(last_swing_high) and ta.crossover(close, last_swing_high) bearish_bos = not na(last_swing_low) and ta.crossunder(close, last_swing_low) if bullish_bos market_structure := 1 // Identify last consolidation (demand zone) before the break demand_top := high[pivot_length] demand_bot := low[pivot_length] demand_active := true last_swing_high := na // Reset after break if bearish_bos market_structure := -1 // Identify last consolidation (supply zone) before the break supply_top := high[pivot_length] supply_bot := low[pivot_length] supply_active := true last_swing_low := na // Reset after break // Invalidate zones if price breaks through them completely if demand_active and close < demand_bot demand_active := false if supply_active and close > supply_top supply_active := false // --- Entry Conditions --- long_condition = market_structure == 1 and demand_active and low <= demand_top and high >= demand_bot short_condition = market_structure == -1 and supply_active and high >= supply_bot and low <= supply_top // --- Strategy Execution --- if long_condition and strategy.position_size == 0 stop_loss = demand_bot risk = close - stop_loss if risk > 0 take_profit = close + (risk * rr_ratio) strategy.entry("Long Demand", strategy.long) strategy.exit("TP/SL Long", "Long Demand", stop=stop_loss, limit=take_profit) demand_active := false if short_condition and strategy.position_size == 0 stop_loss = supply_top risk = stop_loss - close if risk > 0 take_profit = close - (risk * rr_ratio) strategy.entry("Short Supply", strategy.short) strategy.exit("TP/SL Short", "Short Supply", stop=stop_loss, limit=take_profit) supply_active := false // --- Plotting --- plot(last_swing_high, "Swing High", color=color.red, style=plot.style_line, offset=-pivot_length) plot(last_swing_low, "Swing Low", color=color.green, style=plot.style_line, offset=-pivot_length) // Plot active demand zone p_d_top = plot(demand_active ? demand_top : na, "Demand Top", color=color.new(color.green, 50), style=plot.style_line) p_d_bot = plot(demand_active ? demand_bot : na, "Demand Bottom", color=color.new(color.green, 50), style=plot.style_line) fill(p_d_top, p_d_bot, color=demand_active ? color.new(color.green, 85) : na, title="Demand Zone Fill") // Plot active supply zone p_s_top = plot(supply_active ? supply_top : na, "Supply Top", color=color.new(color.red, 50), style=plot.style_line) p_s_bot = plot(supply_active ? supply_bot : na, "Supply Bottom", color=color.new(color.red, 50), style=plot.style_line) fill(p_s_top, p_s_bot, color=supply_active ? color.new(color.red, 85) : na, title="Supply Zone Fill")