OPEN-SOURCE SCRIPT
Zaktualizowano SBP Structural State Detector

SBP Structural State Detector is a rule-based analytical indicator designed to identify confirmed changes between bullish and bearish structural states. It does not attempt to predict exact market tops or bottoms. Instead, it evaluates whether current price behaviour provides sufficient evidence that the prevailing directional state has changed.
The script uses one integrated calculation process. It does not require another indicator, external script, higher-timeframe data source, or manual confirmation tool.
Core Method
The calculation begins by measuring price-path efficiency. This compares the net movement of price with the total distance travelled over the same period. A more direct price path receives a higher efficiency reading, while irregular movement produces a lower reading.
That efficiency value controls the response rate of an internal structural centre. The centre adapts more quickly when price movement is directional and more slowly when movement is noisy. The centre is used internally and is not drawn as a separate trendline.
A volatility-normalized structural band is then calculated around the internal centre. Its width expands when price behaviour is less efficient and contracts when movement becomes more orderly. This makes the visible band responsive to both volatility and market noise rather than relying on a fixed price distance.
Directional qualification uses five related observations:
1. Price location relative to the internal structural centre.
2. Normalized displacement from that centre.
3. Direction of the structural slope.
4. Volatility-normalized momentum.
5. Candle direction, body expansion, and closing location.
A bullish or bearish candidate must receive the required level of evidence and must exceed the evidence supporting the opposite direction. The condition must then persist before it can reach the final event process.
Signal Behaviour
All events are evaluated on confirmed bars.
The final event process enforces strict alternation. After a BUY event, another BUY cannot be accepted until a SALE event has occurred. After a SALE event, another SALE cannot be accepted until a BUY event has occurred.
The Minimum Signal Gap setting specifies the minimum number of confirmed bars required between accepted opposite-direction events. It is a spacing control and does not create same-direction re-entry signals.
Chart Display
The Structural State Band changes colour according to the last accepted directional state:
Green indicates that the last accepted event was bullish.
Red indicates that the last accepted event was bearish.
Gray indicates that no directional event has yet been accepted in the loaded chart history.
BUY and SALE triangles identify accepted state changes. They are placed outside the candle using an ATR-based visual distance so that the markers remain readable without changing their event bar.
Inputs
Minimum Signal Gap: Controls the minimum number of confirmed bars between accepted opposite-direction events.
Show Structural State Band: Shows or hides the volatility- and noise-adjusted state band.
Show BUY / SALE: Shows or hides accepted event markers.
State Band Transparency: Controls only the visual transparency of the band and does not affect calculations or events.
Alerts
Two alert conditions are available:
SBP Structural BUY Event
SBP Structural SALE Event
Alerts should be created through TradingView's Create Alert dialog. Alert behaviour follows confirmed BUY and SALE events generated by the script.
How to Use
Apply the indicator to a standard candlestick or bar chart. Observe the band colour together with accepted BUY and SALE events. The indicator is intended to provide a consistent structural-state reference that can be considered alongside the user's own entry, exit, position-sizing, and risk-management rules.
Limitations
This is an indicator, not a strategy. It does not place orders, calculate position size, provide stop-loss levels, provide profit targets, or report backtested performance.
Signals are based on historical and current confirmed price data. Confirmation introduces delay, especially when price changes direction rapidly. Sideways or volatile markets can produce alternating state changes. The Minimum Signal Gap can reduce closely spaced events but cannot eliminate false or late signals.
The indicator does not guarantee accuracy, profitability, or future market direction. Past chart behaviour does not ensure similar future behaviour. Use standard charts for signal interpretation and conduct independent analysis before making trading decisions.
The script uses one integrated calculation process. It does not require another indicator, external script, higher-timeframe data source, or manual confirmation tool.
Core Method
The calculation begins by measuring price-path efficiency. This compares the net movement of price with the total distance travelled over the same period. A more direct price path receives a higher efficiency reading, while irregular movement produces a lower reading.
That efficiency value controls the response rate of an internal structural centre. The centre adapts more quickly when price movement is directional and more slowly when movement is noisy. The centre is used internally and is not drawn as a separate trendline.
A volatility-normalized structural band is then calculated around the internal centre. Its width expands when price behaviour is less efficient and contracts when movement becomes more orderly. This makes the visible band responsive to both volatility and market noise rather than relying on a fixed price distance.
Directional qualification uses five related observations:
1. Price location relative to the internal structural centre.
2. Normalized displacement from that centre.
3. Direction of the structural slope.
4. Volatility-normalized momentum.
5. Candle direction, body expansion, and closing location.
A bullish or bearish candidate must receive the required level of evidence and must exceed the evidence supporting the opposite direction. The condition must then persist before it can reach the final event process.
Signal Behaviour
All events are evaluated on confirmed bars.
The final event process enforces strict alternation. After a BUY event, another BUY cannot be accepted until a SALE event has occurred. After a SALE event, another SALE cannot be accepted until a BUY event has occurred.
The Minimum Signal Gap setting specifies the minimum number of confirmed bars required between accepted opposite-direction events. It is a spacing control and does not create same-direction re-entry signals.
Chart Display
The Structural State Band changes colour according to the last accepted directional state:
Green indicates that the last accepted event was bullish.
Red indicates that the last accepted event was bearish.
Gray indicates that no directional event has yet been accepted in the loaded chart history.
BUY and SALE triangles identify accepted state changes. They are placed outside the candle using an ATR-based visual distance so that the markers remain readable without changing their event bar.
Inputs
Minimum Signal Gap: Controls the minimum number of confirmed bars between accepted opposite-direction events.
Show Structural State Band: Shows or hides the volatility- and noise-adjusted state band.
Show BUY / SALE: Shows or hides accepted event markers.
State Band Transparency: Controls only the visual transparency of the band and does not affect calculations or events.
Alerts
Two alert conditions are available:
SBP Structural BUY Event
SBP Structural SALE Event
Alerts should be created through TradingView's Create Alert dialog. Alert behaviour follows confirmed BUY and SALE events generated by the script.
How to Use
Apply the indicator to a standard candlestick or bar chart. Observe the band colour together with accepted BUY and SALE events. The indicator is intended to provide a consistent structural-state reference that can be considered alongside the user's own entry, exit, position-sizing, and risk-management rules.
Limitations
This is an indicator, not a strategy. It does not place orders, calculate position size, provide stop-loss levels, provide profit targets, or report backtested performance.
Signals are based on historical and current confirmed price data. Confirmation introduces delay, especially when price changes direction rapidly. Sideways or volatile markets can produce alternating state changes. The Minimum Signal Gap can reduce closely spaced events but cannot eliminate false or late signals.
The indicator does not guarantee accuracy, profitability, or future market direction. Past chart behaviour does not ensure similar future behaviour. Use standard charts for signal interpretation and conduct independent analysis before making trading decisions.
Informacje o Wersji
SBP Structural State Detector is a rule-based overlay designed to identify changes in market structure through one integrated state model. Its purpose is not to print every short-term fluctuation. It evaluates whether price has developed enough directional evidence to justify a change in the active structural state and then maintains a strict BUY-to-SALE sequence.The script is built around a single analytical workflow. An adaptive structural centre measures the path of price, a volatility-adjusted band defines the surrounding state area, directional evidence evaluates whether price is leaving that state with sufficient quality, and confirmed turning points provide an additional delayed validation of structural reversals. Every accepted event is processed by one sequencer.
Adaptive structural centre
The structural centre does not use a fixed response speed. The indicator measures the efficiency of recent price travel by comparing net movement with the total path travelled over the same period.
When price moves in a relatively direct path, the centre responds more quickly. When price becomes noisy and repeatedly changes direction, the centre responds more slowly. This allows the structural reference to adapt to the character of the current price movement rather than using the same sensitivity in every condition.
Volatility-adjusted structural band
The upper and lower boundaries are derived from ATR and expanded when recent price movement is less efficient. The band therefore becomes wider during noisy conditions and more compact when price travels more cleanly.
The filled band is not a conventional support-and-resistance forecast. It is a visual representation of the current structural state area. Its colour follows the most recently accepted BUY or SALE event.
Directional evidence
A possible state transition is evaluated through five related forms of evidence:
1. Price position relative to the adaptive structural centre.
2. Price displacement measured against the volatility-adjusted band.
3. The ATR-normalized slope of the structural centre.
4. Short-horizon momentum normalized by ATR.
5. Candle-release quality, measured from candle direction, body size and closing location.
A transition requires agreement from a defined majority of these conditions. It must also persist across confirmed bars. This persistence requirement is intended to reduce reactions to isolated candles and brief intrabar movement.
Confirmed structural-turn validation
The indicator also validates confirmed local turning points as part of the same structural process. A local high or low is not accepted solely because a pivot exists.
The turning point is evaluated using a pressure reference derived from:
• Candle body pressure
• Closing location within the candle
• Upper-versus-lower wick balance
• Directional movement balance
• ADX participation
The Structural Turn Strength input controls the number of bars required on both sides of the local turn. A higher value identifies broader structural turns but requires more confirmation time.
Confirmed-turn timing
Confirmed structural turns are known only after the required bars on the right side have closed. When accepted, the BUY or SALE label is displayed on the earlier turning-point bar.
This historical placement is for structural clarity. The signal was not available in real time on the earlier bar. Alerts occur on the actual confirmation bar.
Unified BUY and SALE sequence
Immediate state transitions and delayed structural-turn validations are not treated as independent indicator systems. They are two timing stages within the same structural-state model.
All qualified events pass through one sequencer:
BUY → SALE → BUY → SALE
After a BUY is accepted, additional BUY events are blocked until a SALE is accepted. After a SALE is accepted, additional SALE events are blocked until a BUY occurs. This prevents repeated same-direction labels and keeps the display focused on changes in structural direction.
Inputs
Minimum Signal Gap
Controls the minimum number of confirmed bars between accepted opposite-direction state-transition events. Increasing the value reduces signal frequency.
Structural Response Mode
Conservative uses slower pressure smoothing, stricter thresholds and wider confirmed-turn separation.
Balanced provides the default compromise between responsiveness and filtering.
Responsive uses faster smoothing, lower thresholds and shorter confirmed-turn separation.
Structural Turn Strength
Controls how many bars are required on each side of a local high or low before the structural turn is confirmed. Larger values identify broader turns and create a longer confirmation delay.
Show Structural State Band
Shows or hides the adaptive structural band.
Show BUY / SALE
Shows or hides accepted BUY and SALE labels.
State Band Transparency
Controls the transparency of the filled structural band.
How to use the indicator
A green state band indicates that the most recently accepted structural event was BUY. A red state band indicates that the most recently accepted event was SALE.
The band colour represents the current accepted sequence state. It does not guarantee that every candle will continue in that direction.
BUY and SALE labels identify accepted changes in structural direction. They are analytical observations rather than trade orders. Users should independently evaluate market context, liquidity, execution costs, position size and risk.
Chart and timeframe use
Use the indicator on a standard candlestick chart. Its response depends on the selected market and timeframe because ATR, price efficiency, momentum and confirmed turns are calculated from the active chart data.
For publication, the chart should display only this script, normal candles, the symbol, the timeframe and the indicator name. Unrelated scripts and unexplained chart drawings should be removed so the structural band and signals remain clearly identifiable.
Limitations
The indicator works with confirmed bars and does not predict future price movement.
Confirmed structural-turn events are delayed by the selected Structural Turn Strength.
Sideways or rapidly alternating markets can still produce reversals that do not continue.
Higher Structural Turn Strength settings create broader but later turn validation.
Lower response settings can react earlier but may also respond to shorter-lived movement.
The script does not calculate position size, stop loss, profit targets, brokerage, slippage or expected returns.
SBP Structural State Detector is an indicator, not a strategy. It does not place orders, provide performance guarantees or replace independent risk management.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
S B Prasad Trading Ecosystem Email sbptradingecosystem@gmail.com, Mobile no 9903367725
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
S B Prasad Trading Ecosystem Email sbptradingecosystem@gmail.com, Mobile no 9903367725
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.