//@version=5 strategy("PB Blake 2026 Updated Trading Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // ========================================== // 1. INPUTS & CONFIGURATION // ========================================== use_htf = input.bool(true, "Use HTF Trend Filter", group="Trend Bias") htf_timeframe = input.timeframe("15", "HTF Timeframe", group="Trend Bias") swing_lookback = input.int(10, "Swing Lookback (SL Definition)", minval=3, group="Risk Management") rr_ratio = input.float(1.5, "Risk-to-Reward Ratio", minval=0.5, group="Risk Management") // ========================================== // 2. HIGHER TIMEFRAME BIAS (Step 1) // ========================================== htf_ema = request.security(syminfo.tickerid, htf_timeframe, ta.ema(close, 200), barmerge.gaps_off, barmerge.lookahead_off) htf_close = request.security(syminfo.tickerid, htf_timeframe, close, barmerge.gaps_off, barmerge.lookahead_off) bullish_bias = not use_htf or (htf_close > htf_ema) bearish_bias = not use_htf or (htf_close < htf_ema) // ========================================== // 3. KEY LEVELS & FVG DETECTOR (Step 2) // ========================================== // A Fair Value Gap on execution TF consists of 3 candles. // Bullish FVG: Low of bar 0 is greater than High of bar 2 bull_fvg = low[0] > high[2] // Bearish FVG: High of bar 0 is less than Low of bar 2 bear_fvg = high[0] < low[2] // Track active FVGs for Inversion var float last_bull_fvg_bottom = na var bool bull_fvg_active = false var float last_bear_fvg_top = na var bool bear_fvg_active = false if bull_fvg last_bull_fvg_bottom := high[2] bull_fvg_active := true if bear_fvg last_bear_fvg_top := low[2] bear_fvg_active := true // ========================================== // 4. INVERSION FVG (IFVG) DETECTOR (Step 3) // ========================================== // Bullish Inversion: Price closes above the top of an active Bearish FVG bear_fvg_inverted = bear_fvg_active and ta.crossover(close, last_bear_fvg_top) // Bearish Inversion: Price closes below the bottom of an active Bullish FVG bull_fvg_inverted = bull_fvg_active and ta.crossunder(close, last_bull_fvg_bottom) // Reset state once inverted to prevent duplicate entries if bear_fvg_inverted bear_fvg_active := false if bull_fvg_inverted bull_fvg_active := false // ========================================== // 5. TRADE EXECUTION & RISK MANAGEMENT (Step 4) // ========================================== long_condition = bear_fvg_inverted and bullish_bias short_condition = bull_fvg_inverted and bearish_bias if long_condition and strategy.position_size == 0 swing_low = ta.lowest(low, swing_lookback) sl_distance = close - swing_low sl = swing_low tp = close + (sl_distance * rr_ratio) strategy.entry("Long IFVG", strategy.long) strategy.exit("Long Exit", "Long IFVG", stop=sl, limit=tp) if short_condition and strategy.position_size == 0 swing_high = ta.highest(high, swing_lookback) sl_distance = swing_high - close sl = swing_high tp = close - (sl_distance * rr_ratio) strategy.entry("Short IFVG", strategy.short) strategy.exit("Short Exit", "Short IFVG", stop=sl, limit=tp) // ========================================== // VISUALIZATIONS // ========================================== plotshape(long_condition, title="Bullish Entry (Bear FVG Inverted)", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(short_condition, title="Bearish Entry (Bull FVG Inverted)", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small) // Draw active FVG Levels plot(bull_fvg_active ? last_bull_fvg_bottom : na, "Active Bull FVG Inversion Level", color=color.new(color.green, 50), style=plot.style_line) plot(bear_fvg_active ? last_bear_fvg_top : na, "Active Bear FVG Inversion Level", color=color.new(color.red, 50), style=plot.style_line)