OPEN-SOURCE SCRIPT
Structure OS

Make an indicator that OVERVIEW
Structure OS is a price action structure indicator that maps swing highs, swing lows, and structural breaks using a candle pullback confirmation system no lagging indicators, no arbitrary lookback periods.
The indicator runs two independent structure detection engines simultaneously (swing and internal), both using the same confirmation logic but at different structural scopes. A multi-timeframe dashboard provides directional bias and structure state across higher timeframes.
HOW THIS DIFFERS FROM EXISTING OPEN-SOURCE STRUCTURE SCRIPTS
Most publicly available market structure indicators identify swing points using ta.pivothigh() and ta.pivotlow() - fixed-period lookback functions that define a swing high as "the highest point over N bars." This approach produces a flat list of pivot points with no validation that a genuine reversal attempt occurred at those levels.
Structure OS uses a fundamentally different detection method: Instead of a lookback window, the indicator tracks price in real time and requires a sequence of three consecutive opposing candles
each closing beyond the previous one's body - before confirming a swing point. If price exceeds the tracking extreme before three candles complete, the count resets to zero and restarts.
This distinction matters because the same raw price data produces different structural maps depending on which method is used. A fixed-lookback pivot may confirm a swing high that the pullback confirmation method rejects (because the pullback lacked three consecutive candles), and vice versa. Different swing points mean different BOS and CHOCH events, which means entirely different trade signals.
SWING STRUCTURE ENGINE
When price makes a move, the indicator begins tracking a candidate swing point.
Confirmation requires:
Three consecutive opposing candles (bearish candles to confirm a high, bullish to confirm a low) Each candle in the sequence must close beyond the previous one's low (for bearish) or high (for bullish) If price makes a new extreme before three candles complete, the candidate resets and the count starts over
Once two swing points are confirmed, a trading range is established between the swing high and swing low. A candle close beyond the range boundary triggers:
BOS (Break of Structure) - close beyond the swing level in the direction of the current trend. CHOCH (Change of Character) close beyond the swing level against the prevailing trend. Signals reversal.
Confirms continuation.
Wicks through a level do not qualify. Only a candle close beyond the structural level triggers a break event.
Unconfirmed candidate levels are shown as dotted lines so traders can see where a potential swing point is forming before the three-candle count completes.
INTERNAL STRUCTURE ENGINE
Internal structure uses the same
three-candle confirmation logic but is scoped exclusively within the current confirmed swing high and swing low.
It activates only after a new swing point is established. It resets completely when a new swing BOS or CHOCH occurs. It cannot detect or plot structure outside the active swing boundaries.
This separation ensures that pullbacks within a swing range are tracked independently from swing-level reversals. Internal BOS and CHOCH events are labeled as IBOS and iCHOCH respectively, drawn with dashed lines to visually distinguish them from swing structure.
MULTI-TIMEFRAME
DASHBOARD
The on-chart dashboard has two sections:
Directional Bias - Compares the previous candle's close against prior period highs and lows on Weekly and Daily timeframes. Classifies bias as Bullish, Bearish, or neutral based on whether close exceeded the previous period's high or low, or whether a sweep occurred (high/low broken but close returned inside).
Market Structure - Runs the same swing detection engine on H4, 15M, and 1M via request.security(). Reports current bias direction and structure stage (Shift, Confirmed Shift, Expansion, or Continuation) for each timeframe. Only displays timeframes that are higher than thecurrent chart.
SESSION MAPPING
Configurable session highlighting for Asia, London, and New York.
Each session draws a box from session open to close, tracking the high and low in real time. A "Current Week Only" toggle keeps the chart clean by removing older session boxes. All session times, colours, and toggles are independently configurable.
FEATURES
Swing Structure - BOS and CHOCH detection with HH/HL/LH/LL swing labels
Internal Structure - Same 3-candle
logic running inside the current swing range, with independent display settings
Current Range Display - Horizontal lines marking the active swing high and swing low. Solid when confirmed, dotted while tracking Close-Only Break Validation Wicks do not trigger breaks at swing or internal level
Pullback Confirmation - Three
consecutive opposing candles
required. Count resets if price
makes a new extreme
Multi-Timeframe Dashboard
Directional bias (Weekly/Daily) and
market structure state
(H4/15M/1M)
Optional H4 Swing Level Overlay Plots H4 swing high/low as horizontal lines on lower timeframe chartsDirectional bias (Weekly/Daily) and market structure state
(H4/15M/1M)
Optional H4 Swing Level Overlay Plots H4 swing high/low as horizontal lines on lower timeframe charts
Session Mapping - Asia, London, New York with tracked highs/lows Bar Colouring - Optional candle colouring by current swing bias Full Customisation - Independent colour, label size, and BOS/CHOCH toggle settings for both swing and internal structure.
Structure OS is a price action structure indicator that maps swing highs, swing lows, and structural breaks using a candle pullback confirmation system no lagging indicators, no arbitrary lookback periods.
The indicator runs two independent structure detection engines simultaneously (swing and internal), both using the same confirmation logic but at different structural scopes. A multi-timeframe dashboard provides directional bias and structure state across higher timeframes.
HOW THIS DIFFERS FROM EXISTING OPEN-SOURCE STRUCTURE SCRIPTS
Most publicly available market structure indicators identify swing points using ta.pivothigh() and ta.pivotlow() - fixed-period lookback functions that define a swing high as "the highest point over N bars." This approach produces a flat list of pivot points with no validation that a genuine reversal attempt occurred at those levels.
Structure OS uses a fundamentally different detection method: Instead of a lookback window, the indicator tracks price in real time and requires a sequence of three consecutive opposing candles
each closing beyond the previous one's body - before confirming a swing point. If price exceeds the tracking extreme before three candles complete, the count resets to zero and restarts.
This distinction matters because the same raw price data produces different structural maps depending on which method is used. A fixed-lookback pivot may confirm a swing high that the pullback confirmation method rejects (because the pullback lacked three consecutive candles), and vice versa. Different swing points mean different BOS and CHOCH events, which means entirely different trade signals.
SWING STRUCTURE ENGINE
When price makes a move, the indicator begins tracking a candidate swing point.
Confirmation requires:
Three consecutive opposing candles (bearish candles to confirm a high, bullish to confirm a low) Each candle in the sequence must close beyond the previous one's low (for bearish) or high (for bullish) If price makes a new extreme before three candles complete, the candidate resets and the count starts over
Once two swing points are confirmed, a trading range is established between the swing high and swing low. A candle close beyond the range boundary triggers:
BOS (Break of Structure) - close beyond the swing level in the direction of the current trend. CHOCH (Change of Character) close beyond the swing level against the prevailing trend. Signals reversal.
Confirms continuation.
Wicks through a level do not qualify. Only a candle close beyond the structural level triggers a break event.
Unconfirmed candidate levels are shown as dotted lines so traders can see where a potential swing point is forming before the three-candle count completes.
INTERNAL STRUCTURE ENGINE
Internal structure uses the same
three-candle confirmation logic but is scoped exclusively within the current confirmed swing high and swing low.
It activates only after a new swing point is established. It resets completely when a new swing BOS or CHOCH occurs. It cannot detect or plot structure outside the active swing boundaries.
This separation ensures that pullbacks within a swing range are tracked independently from swing-level reversals. Internal BOS and CHOCH events are labeled as IBOS and iCHOCH respectively, drawn with dashed lines to visually distinguish them from swing structure.
MULTI-TIMEFRAME
DASHBOARD
The on-chart dashboard has two sections:
Directional Bias - Compares the previous candle's close against prior period highs and lows on Weekly and Daily timeframes. Classifies bias as Bullish, Bearish, or neutral based on whether close exceeded the previous period's high or low, or whether a sweep occurred (high/low broken but close returned inside).
Market Structure - Runs the same swing detection engine on H4, 15M, and 1M via request.security(). Reports current bias direction and structure stage (Shift, Confirmed Shift, Expansion, or Continuation) for each timeframe. Only displays timeframes that are higher than thecurrent chart.
SESSION MAPPING
Configurable session highlighting for Asia, London, and New York.
Each session draws a box from session open to close, tracking the high and low in real time. A "Current Week Only" toggle keeps the chart clean by removing older session boxes. All session times, colours, and toggles are independently configurable.
FEATURES
Swing Structure - BOS and CHOCH detection with HH/HL/LH/LL swing labels
Internal Structure - Same 3-candle
logic running inside the current swing range, with independent display settings
Current Range Display - Horizontal lines marking the active swing high and swing low. Solid when confirmed, dotted while tracking Close-Only Break Validation Wicks do not trigger breaks at swing or internal level
Pullback Confirmation - Three
consecutive opposing candles
required. Count resets if price
makes a new extreme
Multi-Timeframe Dashboard
Directional bias (Weekly/Daily) and
market structure state
(H4/15M/1M)
Optional H4 Swing Level Overlay Plots H4 swing high/low as horizontal lines on lower timeframe chartsDirectional bias (Weekly/Daily) and market structure state
(H4/15M/1M)
Optional H4 Swing Level Overlay Plots H4 swing high/low as horizontal lines on lower timeframe charts
Session Mapping - Asia, London, New York with tracked highs/lows Bar Colouring - Optional candle colouring by current swing bias Full Customisation - Independent colour, label size, and BOS/CHOCH toggle settings for both swing and internal structure.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.