OPEN-SOURCE SCRIPT
Multi-Timeframe Break of Structure Engine

Multi-Timeframe Break of Structure Engine is a confluence-based structure tool that detects break-of-structure events on an execution timeframe, then filters those events through two higher-timeframe trend layers before signaling.
This script is designed for traders who want structure events in context, rather than isolated break signals.
What this script does
The script has four connected jobs:
1. Detects bullish and bearish break-of-structure events on a chosen structure timeframe.
2. Validates directional context with two higher-timeframe filters.
3. Tracks the active BOS level and monitors first retest behavior.
4. Emits separate event classes for raw structure events and fully aligned confluence signals.
The practical goal is to reduce low-context entries and keep the chart focused on structure levels that still matter.
How the model is built
The logic is based on three directional layers plus state management:
1. Macro Layer 1
This is the highest trend layer (default Daily). It uses a fast/slow moving-average relationship to define broad directional bias.
2. Macro Layer 2
This is an intermediate confirmation layer (default 4H). It combines fast/slow MA direction with close relative to a short MA, so intermediate momentum must also agree with bias.
3. Structure Layer
This is the execution layer (default 15m). BOS events are detected from structure-timeframe closes relative to prior structure swing references.
A BOS event becomes an aligned signal only when all three layers agree with its direction.
Core BOS logic
Bullish BOS logic:

- Structure close breaks above prior structure swing reference.
- Optional strength filter can require the break candle body to be larger than average by a multiplier.
- Macro and structure layers are evaluated for directional agreement.
Bearish BOS logic:

- Structure close breaks below prior structure swing reference.
- Optional strength filter works symmetrically.
- Macro and structure layers are evaluated for directional agreement.
The script evaluates BOS events on structure-bar transitions, which helps avoid repeated triggers from lower-timeframe bar noise during a single structure candle.
Retest logic
After a BOS level is created, the script tracks one active BOS level and evaluates first retest conditions.
Two retest modes are available:
1. Wick Touch
Retest requires direct contact with the BOS level and directional close behavior.
2. ATR Proximity
Retest can qualify within a volatility-adjusted distance from the level using structure-timeframe ATR and a user-defined multiplier.
This dual mode is useful because low-volatility instruments often respect precise touches, while high-volatility instruments may react near a level without exact contact.
Validity window behavior
The optional validity window expires BOS levels that remain unretested for too long.
If enabled, validity duration is measured in structure bars. This keeps the level lifecycle aligned with the same timeframe where BOS is detected, rather than chart bars that may be faster or slower than the structure context.
Why this script can be useful
The script is not a single trigger line. It combines:
- directional context from higher timeframes,
- structure break detection on execution timeframe,
- persistent level tracking,
- retest qualification,
- optional expiration logic.
This interaction is intended to reduce low-quality breakout noise and keep attention on structure events that are still contextually relevant.
What is plotted
1. Optional MA overlays
- Structure fast and slow MA.
- Macro 1 fast and slow MA.
- Macro 2 price/fast/slow MA.
2. Signal markers
- BOS long/short markers for aligned BOS.
- Retest long/short markers for aligned retests.
3. Active BOS level line
- Horizontal level extends until retest or replacement by a new BOS event.
- Optional right-side BOS price label.
4. Optional alignment dashboard
- Macro 1 state.
- Macro 2 state.
- Structure state.
- Final alignment state.
How to use it in a practical workflow
Example workflow:
1. Set structure timeframe for execution rhythm
Scalping-style execution usually uses lower structure values.
Intraday continuation often uses moderate structure values.
Swing continuation uses higher structure values.
2. Keep higher-timeframe context logical
A common approach is Macro 1 above Macro 2 above Structure so each layer has a distinct role.
3. Wait for alignment first
Use alignment as context. Do not treat any single output in isolation.
4. Use BOS as setup creation
A new BOS indicates potential directional continuation under confluence.
5. Use retest as conditional confirmation
Retest can help refine entries after initial break.
6. Manage invalidation separately
The script does not replace personal risk management, stop placement, or position sizing.
Input groups and what they control
Structure Timeframe Settings
- Structure Timeframe: execution structure context.
- Structure MA Type: EMA or SMA for structure trend.
- Structure Fast/Slow Lengths: structure trend sensitivity.
Macro Layer 1 Settings
- Macro 1 Timeframe: broad trend context.
- Macro 1 Fast/Slow Lengths: sensitivity of broad trend filter.
- Macro 1 MA Type: EMA or SMA behavior choice.
Macro Layer 2 Settings
- Macro 2 Timeframe: intermediate filter.
- Macro 2 Fast/Slow Lengths: trend filter sensitivity.
- Macro 2 Price MA Length: participation filter via close relative to short MA.
- Macro 2 MA Type: EMA or SMA behavior choice.
Candle Close Confirmation
- Wait for candle close: event gating behavior on chart bars.
BOS Advanced Filters
- Enable BOS validity window: controls expiration behavior.
- BOS validity (structure bars): expiration duration.
- Enable BOS strength filter: optional quality threshold on break candle body.
- Min body size multiplier: strength threshold.
- Show BOS labels: level label visibility.
- Max stored BOS lines: line object management limit.
Retest Detection Settings
- Retest method: Wick Touch or ATR Proximity.
- ATR Period: volatility measurement period for proximity mode.
- ATR Proximity Factor: allowable near-level distance in ATR terms.
Display Options
- Show structure and macro MA overlays.
- Show dashboard table.
Colors and Labels
- Bullish and bearish display colors.
- BOS label text color.
- Label right offset.
Alert architecture
The script provides alert conditions for:
- aligned BOS long/short,
- aligned retest long/short,
- alignment flips,
- raw BOS creation events,
- raw retest events,
- macro and structure trend flips.
This allows users to build different alert workflows:
- conservative workflow uses aligned BOS/retest alerts only,
- contextual workflow also monitors alignment flips,
- diagnostic workflow includes raw events for observation.
Market and timeframe suitability
This script can be used on:
- crypto,
- forex,
- indices,
- equities,
- commodities.
Execution styles it can support:
1. Scalping-style continuation
- Lower structure timeframe.
- Generally stricter retest conditions.
- Faster context changes and more signal frequency.
2. Intraday trend continuation
- Moderate structure timeframe.
- Typical use of both BOS and retest phases.
- Good balance between responsiveness and filtering.
3. Swing continuation
- Higher structure timeframe.
- Often benefits from ATR Proximity retest mode.
- Lower signal frequency, broader moves.
Style suitability depends on parameter choices and instrument volatility.
Interpretation guidance and limitations
Important limitations:
1. This is a context and structure tool, not a profit guarantee tool.
2. Trend filters may lag near turning points.
3. Strength filters reduce noise but may skip early break phases.
4. ATR Proximity can become loose if multiplier is set too high.
5. BOS logic can still produce false continuation in choppy, mean-reverting conditions.
Because of this, risk management remains mandatory.
How this differs from a basic single-layer BOS script
This script does not only mark local breaks. It manages an interaction chain:
- structure event detection,
- multi-timeframe agreement,
- stateful BOS level tracking,
- retest qualification modes,
- level validity expiration.
The objective is cleaner structure context and better workflow discipline, not maximizing raw signal count.
Responsible usage notes
- Start with default values, then adjust gradually.
- Test one variable at a time.
- Keep notes on which settings are used per market and session.
- Validate behavior in replay before using alerts live.
Disclaimer
This script is an analytical support tool. It is not financial advice and does not guarantee outcomes. Trading involves risk. Users are responsible for trade selection, position sizing, and risk control.
This script is designed for traders who want structure events in context, rather than isolated break signals.
What this script does
The script has four connected jobs:
1. Detects bullish and bearish break-of-structure events on a chosen structure timeframe.
2. Validates directional context with two higher-timeframe filters.
3. Tracks the active BOS level and monitors first retest behavior.
4. Emits separate event classes for raw structure events and fully aligned confluence signals.
The practical goal is to reduce low-context entries and keep the chart focused on structure levels that still matter.
How the model is built
The logic is based on three directional layers plus state management:
1. Macro Layer 1
This is the highest trend layer (default Daily). It uses a fast/slow moving-average relationship to define broad directional bias.
2. Macro Layer 2
This is an intermediate confirmation layer (default 4H). It combines fast/slow MA direction with close relative to a short MA, so intermediate momentum must also agree with bias.
3. Structure Layer
This is the execution layer (default 15m). BOS events are detected from structure-timeframe closes relative to prior structure swing references.
A BOS event becomes an aligned signal only when all three layers agree with its direction.
Core BOS logic
Bullish BOS logic:
- Structure close breaks above prior structure swing reference.
- Optional strength filter can require the break candle body to be larger than average by a multiplier.
- Macro and structure layers are evaluated for directional agreement.
Bearish BOS logic:
- Structure close breaks below prior structure swing reference.
- Optional strength filter works symmetrically.
- Macro and structure layers are evaluated for directional agreement.
The script evaluates BOS events on structure-bar transitions, which helps avoid repeated triggers from lower-timeframe bar noise during a single structure candle.
Retest logic
After a BOS level is created, the script tracks one active BOS level and evaluates first retest conditions.
Two retest modes are available:
1. Wick Touch
Retest requires direct contact with the BOS level and directional close behavior.
2. ATR Proximity
Retest can qualify within a volatility-adjusted distance from the level using structure-timeframe ATR and a user-defined multiplier.
This dual mode is useful because low-volatility instruments often respect precise touches, while high-volatility instruments may react near a level without exact contact.
Validity window behavior
The optional validity window expires BOS levels that remain unretested for too long.
If enabled, validity duration is measured in structure bars. This keeps the level lifecycle aligned with the same timeframe where BOS is detected, rather than chart bars that may be faster or slower than the structure context.
Why this script can be useful
The script is not a single trigger line. It combines:
- directional context from higher timeframes,
- structure break detection on execution timeframe,
- persistent level tracking,
- retest qualification,
- optional expiration logic.
This interaction is intended to reduce low-quality breakout noise and keep attention on structure events that are still contextually relevant.
What is plotted
1. Optional MA overlays
- Structure fast and slow MA.
- Macro 1 fast and slow MA.
- Macro 2 price/fast/slow MA.
2. Signal markers
- BOS long/short markers for aligned BOS.
- Retest long/short markers for aligned retests.
3. Active BOS level line
- Horizontal level extends until retest or replacement by a new BOS event.
- Optional right-side BOS price label.
4. Optional alignment dashboard
- Macro 1 state.
- Macro 2 state.
- Structure state.
- Final alignment state.
How to use it in a practical workflow
Example workflow:
1. Set structure timeframe for execution rhythm
Scalping-style execution usually uses lower structure values.
Intraday continuation often uses moderate structure values.
Swing continuation uses higher structure values.
2. Keep higher-timeframe context logical
A common approach is Macro 1 above Macro 2 above Structure so each layer has a distinct role.
3. Wait for alignment first
Use alignment as context. Do not treat any single output in isolation.
4. Use BOS as setup creation
A new BOS indicates potential directional continuation under confluence.
5. Use retest as conditional confirmation
Retest can help refine entries after initial break.
6. Manage invalidation separately
The script does not replace personal risk management, stop placement, or position sizing.
Input groups and what they control
Structure Timeframe Settings
- Structure Timeframe: execution structure context.
- Structure MA Type: EMA or SMA for structure trend.
- Structure Fast/Slow Lengths: structure trend sensitivity.
Macro Layer 1 Settings
- Macro 1 Timeframe: broad trend context.
- Macro 1 Fast/Slow Lengths: sensitivity of broad trend filter.
- Macro 1 MA Type: EMA or SMA behavior choice.
Macro Layer 2 Settings
- Macro 2 Timeframe: intermediate filter.
- Macro 2 Fast/Slow Lengths: trend filter sensitivity.
- Macro 2 Price MA Length: participation filter via close relative to short MA.
- Macro 2 MA Type: EMA or SMA behavior choice.
Candle Close Confirmation
- Wait for candle close: event gating behavior on chart bars.
BOS Advanced Filters
- Enable BOS validity window: controls expiration behavior.
- BOS validity (structure bars): expiration duration.
- Enable BOS strength filter: optional quality threshold on break candle body.
- Min body size multiplier: strength threshold.
- Show BOS labels: level label visibility.
- Max stored BOS lines: line object management limit.
Retest Detection Settings
- Retest method: Wick Touch or ATR Proximity.
- ATR Period: volatility measurement period for proximity mode.
- ATR Proximity Factor: allowable near-level distance in ATR terms.
Display Options
- Show structure and macro MA overlays.
- Show dashboard table.
Colors and Labels
- Bullish and bearish display colors.
- BOS label text color.
- Label right offset.
Alert architecture
The script provides alert conditions for:
- aligned BOS long/short,
- aligned retest long/short,
- alignment flips,
- raw BOS creation events,
- raw retest events,
- macro and structure trend flips.
This allows users to build different alert workflows:
- conservative workflow uses aligned BOS/retest alerts only,
- contextual workflow also monitors alignment flips,
- diagnostic workflow includes raw events for observation.
Market and timeframe suitability
This script can be used on:
- crypto,
- forex,
- indices,
- equities,
- commodities.
Execution styles it can support:
1. Scalping-style continuation
- Lower structure timeframe.
- Generally stricter retest conditions.
- Faster context changes and more signal frequency.
2. Intraday trend continuation
- Moderate structure timeframe.
- Typical use of both BOS and retest phases.
- Good balance between responsiveness and filtering.
3. Swing continuation
- Higher structure timeframe.
- Often benefits from ATR Proximity retest mode.
- Lower signal frequency, broader moves.
Style suitability depends on parameter choices and instrument volatility.
Interpretation guidance and limitations
Important limitations:
1. This is a context and structure tool, not a profit guarantee tool.
2. Trend filters may lag near turning points.
3. Strength filters reduce noise but may skip early break phases.
4. ATR Proximity can become loose if multiplier is set too high.
5. BOS logic can still produce false continuation in choppy, mean-reverting conditions.
Because of this, risk management remains mandatory.
How this differs from a basic single-layer BOS script
This script does not only mark local breaks. It manages an interaction chain:
- structure event detection,
- multi-timeframe agreement,
- stateful BOS level tracking,
- retest qualification modes,
- level validity expiration.
The objective is cleaner structure context and better workflow discipline, not maximizing raw signal count.
Responsible usage notes
- Start with default values, then adjust gradually.
- Test one variable at a time.
- Keep notes on which settings are used per market and session.
- Validate behavior in replay before using alerts live.
Disclaimer
This script is an analytical support tool. It is not financial advice and does not guarantee outcomes. Trading involves risk. Users are responsible for trade selection, position sizing, and risk control.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。