1. Component Deconstruction¶
Structure & Volatility Indicators¶
Pivot High / Pivot Low (
ta.pivothigh,ta.pivotlow)Specific Configuration:
source:highforpivothigh,lowforpivotlow.leftbars:pivotLength(default: 3).rightbars:pivotLength(default: 3).
Functional Modification: The script does not use the raw output of these functions directly in the trigger logic. Instead, it uses them to update two state variables,
lastPivotHighandlastPivotLow, declared with thevarkeyword. This modification transforms the pivot functions from a simple plot into a stateful tracking mechanism. The variableslastPivotHighandlastPivotLowperpetually hold the price value of the most recently confirmed pivot, creating a dynamic, horizontal support/resistance level that persists across subsequent bars until a new pivot is formed.
Average True Range (
ta.atr)Specific Configuration:
length: 14 (hard-coded). This is the standard lookback period.
Functional Modification: The ATR value is not used as a direct signal. Its sole purpose is to serve as a dynamic unit of measurement for market volatility. It is multiplied by the
atrMultinput to create a volatility-normalized threshold (currentAtr * atrMult). This threshold defines the maximum allowable price range for a valid consolidation period.
Highest High / Lowest Low (
ta.highest,ta.lowest)Specific Configuration:
source:high[1]forta.highest,low[1]forta.lowest. The[1]offset is critical, as it ensures the calculation is performed on closed bars, excluding the current, developing bar.length:consLength(default: 10).
Functional Modification: These functions are used to calculate the
zoneRange(pastHigh - pastLow). This value represents the absolute price range over the specified lookback period. It is the core input for the consolidation filter.
2. Logic Layering & Confluence¶
The script’s engine is built on a hierarchical filtering model where multiple conditions must be met sequentially or concurrently. A signal is only generated if it passes through all logical gates.
Gatekeeper 1: The Consolidation Filter (
isConsolidating)Interaction Dynamics: This is the primary filter that determines if the market is in a state of low-volatility compression suitable for a breakout.
Hierarchical Filtering: It acts as the first major gatekeeper. The logic is
zoneRange <= (currentAtr * atrMult).The script first calculates the absolute price range (
zoneRange) over theconsLengthperiod.It then calculates the maximum allowed range by scaling the current 14-period ATR by the
atrMultfactor.A
truestate is achieved only if the observed range is less than or equal to this volatility-adjusted threshold. If this condition is false, no breakout signal can be generated, regardless of price action. This filter effectively reduces the signal-to-noise ratio by ignoring breakouts from high-volatility, choppy environments.
Gatekeeper 2: The Cooldown Filter (
canEnter)Interaction Dynamics: This filter is purely temporal and serves to prevent signal clustering and over-trading.
Hierarchical Filtering: It functions as a time-based lock. The logic is
bar_index - lastTradeBar >= cooldownBars.The script maintains a state variable,
lastTradeBar, which records the bar index of the last valid signal.For each new bar, it checks if the number of bars elapsed since the last signal is greater than or equal to the
cooldownBarsinput.If this condition is false, the
canEnterflag isfalse, and the execution engine is blocked, even if all other structural and volatility conditions are met.
Gatekeeper 3: The Structural Confirmation Filter
Interaction Dynamics: This filter validates the integrity of the breakout move itself, looking for a classic market structure pattern.
Hierarchical Filtering: This is a final confirmation layer applied concurrently with the breakout trigger.
For Longs: The condition
low > lastPivotLowmust be true. This ensures that the breakout candle’s low is higher than the most recent significant swing low. It filters out breakouts where price spikes above resistance but immediately violates the underlying support structure.For Shorts: The condition
high < lastPivotHighmust be true. This confirms the breakout candle’s high is lower than the most recent significant swing high, validating the bearish pressure.
3. The Execution Engine¶
The final trigger is a boolean AND operation across all filtered conditions.
Boolean Logic: Long Trigger (
bullishBreakout) Atruesignal is returned if and only if all of the following are true on the same bar:isBullishCandle: The candle’scloseis greater than itsopen.ta.crossover(close, lastPivotHigh): The closing price crosses above the stored value of the last confirmed pivot high. This is the primary catalyst.low > lastPivotLow: The low of the breakout candle is higher than the last confirmed pivot low (Structural Confirmation).isConsolidating: The Consolidation Filter is permissive.canEnter: The Cooldown Filter is permissive.
Boolean Logic: Short Trigger (
bearishBreakout) Atruesignal is returned if and only if all of the following are true on the same bar:isBearishCandle: The candle’scloseis less than itsopen.ta.crossunder(close, lastPivotLow): The closing price crosses below the stored value of the last confirmed pivot low. This is the primary catalyst.high < lastPivotHigh: The high of the breakout candle is lower than the last confirmed pivot high (Structural Confirmation).isConsolidating: The Consolidation Filter is permissive.canEnter: The Cooldown Filter is permissive.
Mathematical Constants & Risk Profile
Risk Calculation: The risk is defined structurally, not by a fixed value or volatility measure.
Long Risk:
risk = entryPrice - stopPrice, whereentryPriceiscloseandstopPriceislastPivotLow.Short Risk:
risk = stopPrice - entryPrice, whereentryPriceiscloseandstopPriceislastPivotHigh. This methodology ties the trade’s risk directly to the market structure preceding the breakout. A wider consolidation range naturally results in a larger initial risk.
Target Calculation (
targetMult): The take-profit level is a direct function of the calculated risk.Long Target:
targetPrice = entryPrice + (risk * targetMult).Short Target:
targetPrice = entryPrice - (risk * targetMult). ThetargetMult(default: 2.0) is a hard-coded multiplier that establishes a fixed risk-to-reward ratio for every trade. A value of 2.0 enforces a 1:2 risk-reward profile. This constant is the primary determinant of the strategy’s potential profitability per trade.