//@version=5 strategy("The A+ Market Mechanics Strategy", 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 & PARAMETERS // ========================================== swing_length = input.int(10, "Swing Structure Pivot Length", minval=3, tooltip="Bar length used to identify major HTF swing highs/lows") int_length = input.int(3, "Internal Structure Pivot Length", minval=1, tooltip="Bar length used to identify internal sub-structure pivots") rr_ratio = input.float(2.5, "Risk to Reward Ratio (R:R)", minval=1.0, step=0.1) atr_period = input.int(14, "ATR Period for SL Buffer") atr_mult = input.float(0.5, "ATR Stop Loss Buffer Multiplier", minval=0.0, step=0.1) // ========================================== // STRUCTURE CALCULATIONS // ========================================== // Major Swing Structure Pivots swing_ph = ta.pivothigh(high, swing_length, swing_length) swing_pl = ta.pivotlow(low, swing_length, swing_length) // Internal Structure Pivots int_ph = ta.pivothigh(high, int_length, int_length) int_pl = ta.pivotlow(low, int_length, int_length) var float swing_high = na var float swing_low = na var int htf_trend = 0 // 1 = Bullish, -1 = Bearish if not na(swing_ph) swing_high := high[swing_length] if not na(swing_pl) swing_low := low[swing_length] // Determine HTF Swing Break of Structure (BOS) if not na(swing_high) and ta.crossover(close, swing_high) htf_trend := 1 if not na(swing_low) and ta.crossunder(close, swing_low) htf_trend := -1 // Equilibrium Level (50% Discount / Premium Filter) equilibrium = (swing_high + swing_low) / 2.0 is_discount = not na(equilibrium) and close < equilibrium is_premium = not na(equilibrium) and close > equilibrium // Internal Structure Tracking var float last_int_ph = na var float last_int_pl = na if not na(int_ph) last_int_ph := high[int_length] if not na(int_pl) last_int_pl := low[int_length] // Internal Market Shift (CHoCH / Change of Character) bullish_choch = (htf_trend == 1) and is_discount and not na(last_int_ph) and ta.crossover(close, last_int_ph) bearish_choch = (htf_trend == -1) and is_premium and not na(last_int_pl) and ta.crossunder(close, last_int_pl) // ========================================== // RISK & POSITION EXECUTION // ========================================== atr_val = ta.atr(atr_period) var float long_sl = na var float long_tp = na var float short_sl = na var float short_tp = na if bullish_choch and strategy.position_size == 0 long_sl := (na(last_int_pl) ? low : last_int_pl) - (atr_val * atr_mult) risk = close - long_sl if risk > 0 long_tp := close + (risk * rr_ratio) strategy.entry("A+ Long", strategy.long) strategy.exit("Exit Long", "A+ Long", stop=long_sl, limit=long_tp) if bearish_choch and strategy.position_size == 0 short_sl := (na(last_int_ph) ? high : last_int_ph) + (atr_val * atr_mult) risk = short_sl - close if risk > 0 short_tp := close - (risk * rr_ratio) strategy.entry("A+ Short", strategy.short) strategy.exit("Exit Short", "A+ Short", stop=short_sl, limit=short_tp) // ========================================== // VISUALIZATION // ========================================== plot(swing_high, "Swing High", color=color.new(color.green, 30), linewidth=2) plot(swing_low, "Swing Low", color=color.new(color.red, 30), linewidth=2) plot(equilibrium, "Equilibrium (50%)", color=color.new(color.orange, 20), linewidth=1) plotshape(bullish_choch and strategy.position_size[1] == 0, title="Bullish A+ Setup", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(bearish_choch and strategy.position_size[1] == 0, title="Bearish A+ Setup", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)