Most traders view a breakout as a race to the entry button. At http://codon.pro, we view it as a hypothesis that requires rigorous verification.

This open-source Pine Script v6 framework is designed to remove emotional friction by translating top-tier structural analysis into mechanical execution.

The Logic: Precision Over Anticipation

Unlike standard breakout indicators that clutter your chart with stale information, our framework operates on a three-stage validation protocol:

1. Dynamic Range Detection: Automatically identifies consolidation zones over a 50-bar lookback on the H4 timeframe. We define the battleground before the fight begins.

2. State-Persistent Monitoring: Upon breakout, the system enters an "Active Waiting" state. We’ve integrated a Signal Decay filter that automatically invalidates outdated structures, ensuring you only track liquidity that still matters.

3. The Rejection Filter: Entry is triggered only when price returns to the level and produces a bullish confirmation. We require the market to "declare itself" twice: once for the breakout, and once for the defense.

In a world full of noise, we choose to build. We choose to react. We choose precision.

The full open-source script is attached in the thread below.

Architecture precedes execution. Logic over bias.

The full Pine Script v6 is below.

// © chttp://ccodon.pro_Architect

=6
strategy("http://codon.pro | Structural Retest System", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// ==========================================
// User Inputs
// ==========================================
string GRP_STRUC = "Structure Definitions"
int lookback = http://input.int(50, "Range Lookback Length", minval=10, group=GRP_STRUC, tooltip="Period to define the consolidation range")
float tolerance_pct = input.float(0.8, "Retest Tolerance %", minval=0.1, step=0.1, group=GRP_STRUC) / 100
int timeout_bars = http://input.int(30, "Signal Timeout (Bars)", minval=5, group=GRP_STRUC, tooltip="Auto-reset stale signals")

string GRP_RISK = "Risk Management"
float sl_atr_mult = input.float(2.0, "Stop Loss ATR Multiplier", group=GRP_RISK)
float tp_rr_ratio = input.float(2.5, "Take Profit (R:R) Ratio", group=GRP_RISK)

// ==========================================
// Core Logic
// ==========================================

// 1. Define the Range
float range_high = ta.highest(high[1], lookback)
float range_low = ta.lowest(low[1], lookback)

// 2. State Management
var bool is_waiting = false
var float target_level = na
var int bars_since_breakout = 0

// 3. Breakout Detection & Re-calibration
bool new_breakout = close > range_high and strategy.position_size == 0

if new_breakout
is_waiting := true
target_level := range_high
bars_since_breakout := 0

// 4. Timeout & Invalidation Logic (Signal Decay)
if is_waiting
bars_since_breakout += 1
if bars_since_breakout > timeout_bars or close < range_low
is_waiting := false
target_level := na
bars_since_breakout := 0

// 5. Retest & Confirmation Logic
float zone_upper = target_level (1 + tolerance_pct)
float zone_lower = target_level (1 - tolerance_pct)
bool is_retesting = is_waiting and low <= zone_upper and low >= zone_lower
bool confirmation = is_retesting and close > open

// 6. Execution Strategy
if confirmation
strategy.entry("Long", strategy.long, comment="Retest_Confirmed")
is_waiting := false
target_level := na
bars_since_breakout := 0

// ==========================================
// Risk Management (Exits)
// ==========================================
float atr = ta.atr(14)
float sl_price = strategy.position_avg_price - (atr sl_atr_mult)
float tp_price = strategy.position_avg_price + (atr sl_atr_mult * tp_rr_ratio)

if strategy.position_size > 0
strategy.exit("Exit", "Long", stop=sl_price, limit=tp_price, comment_loss="SL_Hit", comment_profit="TP_Hit")

// ==========================================
// Visualizations
// ==========================================
plot(range_high, "Structural Resistance", http://color.new(color.gray, 50), 1, http://plot.style_linebr)
plot(range_low, "Structural Support", http://color.new(color.gray, 50), 1, http://plot.style_linebr)
plot(is_waiting ? target_level : na, "Active Retest Zone", http://color.blue, 2, http://plot.style_circles)
bgcolor(is_waiting ? http://color.new(http://color.blue, 92) : na)

//

Keep Reading