OPEN-SOURCE SCRIPT
Trend State Signals

Trend State Signals is an adaptive trend-state indicator designed to identify changes in market direction while filtering out insignificant price fluctuations.
Instead of reacting to every short-term price movement, the indicator updates its state only when price travels far enough to exceed a dynamically calculated movement threshold.
The result is a step-like trend line that remains stable during periods of market noise and changes direction only after a meaningful price movement has occurred.
Unlike many traditional trend-following indicators that continuously track price, Trend State Signals intentionally ignores minor fluctuations, providing a cleaner and more objective view of whether the market is currently in a bullish or bearish state.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚙️ How It Works
The indicator estimates the current level of market activity by measuring the average absolute price movement over a user-defined lookback period.
Unlike many similar indicators, ATR is not used. Instead, the calculation follows these steps:
✔️ The absolute price change is calculated for every bar.
✔️ These values are smoothed using a Running Moving Average (RMA).
✔️ The smoothed result becomes a dynamic estimate of current market volatility.
✔️ This value is multiplied by the Range Multiplier, defining the minimum distance price must travel before the filter is allowed to update.
This adaptive threshold determines how far price must move before the internal filter changes its position.
If price remains inside the calculated range, the filter stays unchanged.
Once price exceeds that range, the filter shifts toward price while maintaining the adaptive distance.
Because the filter only updates after meaningful price expansion, the indicator naturally filters out a large amount of random market noise and significantly reduces unnecessary trend changes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Trend State Detection
The market state is determined solely by the direction of the adaptive filter.
🟢 Filter moving upward → Bullish
🔴 Filter moving downward → Bearish
⚪ Filter unchanged → Previous market state is maintained
Signals are generated only when the filter changes direction.
Rather than producing continuous buy or sell signals on every candle, the indicator highlights transitions between bullish and bearish market environments.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Signal Confirmation
The indicator includes an optional signal confirmation mode.
When Confirm Signals On Bar Close is enabled, a new trend state is confirmed only after the current candle has closed.
When disabled, trend changes can appear immediately while the current bar is still forming.
This allows traders to choose between earlier signals or additional confirmation.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎛 Settings
Sensitivity Length
Defines the lookback period used to calculate the average market movement.
• Lower values make the indicator more responsive.
• Higher values produce a smoother adaptive filter.
Range Multiplier
Controls how much price movement is required before the filter changes its state.
Higher values
✔️ Fewer trend changes
✔️ Stronger noise filtering
✔️ Smoother trend line
Lower values
✔️ Earlier reactions
✔️ More frequent state changes
✔️ Higher sensitivity
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎨 Visual Features
The indicator includes several independent visualization options, each of which can be enabled or disabled separately.
✔️ Adaptive Trend Line
✔️ Glow Effect
✔️ Gradient Ribbon Between Price and Filter
✔️ Bullish / Bearish Transition Labels
✔️ Optional Candle Coloring
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔔 Alerts
Two alert conditions are available.
🟢 Bullish Trend State
🔴 Bearish Trend State
Alerts are triggered only when a new trend state is confirmed according to the selected confirmation mode.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 Typical Use
Trend State Signals is primarily designed as a market state filter rather than a complete trading system.
It can be used to:
✔️ Identify the dominant market direction
✔️ Filter signals generated by other trading strategies
✔️ Trade only in the direction of the prevailing trend
✔️ Reduce trades caused by short-term market noise
Like any trend-following methodology, the indicator confirms trend changes only after the market has moved a sufficient distance. As a result, signals may appear after the initial turning point. This is an intentional design choice that helps reduce the impact of random price fluctuations while improving trend stability.
Instead of reacting to every short-term price movement, the indicator updates its state only when price travels far enough to exceed a dynamically calculated movement threshold.
The result is a step-like trend line that remains stable during periods of market noise and changes direction only after a meaningful price movement has occurred.
Unlike many traditional trend-following indicators that continuously track price, Trend State Signals intentionally ignores minor fluctuations, providing a cleaner and more objective view of whether the market is currently in a bullish or bearish state.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚙️ How It Works
The indicator estimates the current level of market activity by measuring the average absolute price movement over a user-defined lookback period.
Unlike many similar indicators, ATR is not used. Instead, the calculation follows these steps:
✔️ The absolute price change is calculated for every bar.
✔️ These values are smoothed using a Running Moving Average (RMA).
✔️ The smoothed result becomes a dynamic estimate of current market volatility.
✔️ This value is multiplied by the Range Multiplier, defining the minimum distance price must travel before the filter is allowed to update.
This adaptive threshold determines how far price must move before the internal filter changes its position.
If price remains inside the calculated range, the filter stays unchanged.
Once price exceeds that range, the filter shifts toward price while maintaining the adaptive distance.
Because the filter only updates after meaningful price expansion, the indicator naturally filters out a large amount of random market noise and significantly reduces unnecessary trend changes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Trend State Detection
The market state is determined solely by the direction of the adaptive filter.
🟢 Filter moving upward → Bullish
🔴 Filter moving downward → Bearish
⚪ Filter unchanged → Previous market state is maintained
Signals are generated only when the filter changes direction.
Rather than producing continuous buy or sell signals on every candle, the indicator highlights transitions between bullish and bearish market environments.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Signal Confirmation
The indicator includes an optional signal confirmation mode.
When Confirm Signals On Bar Close is enabled, a new trend state is confirmed only after the current candle has closed.
When disabled, trend changes can appear immediately while the current bar is still forming.
This allows traders to choose between earlier signals or additional confirmation.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎛 Settings
Sensitivity Length
Defines the lookback period used to calculate the average market movement.
• Lower values make the indicator more responsive.
• Higher values produce a smoother adaptive filter.
Range Multiplier
Controls how much price movement is required before the filter changes its state.
Higher values
✔️ Fewer trend changes
✔️ Stronger noise filtering
✔️ Smoother trend line
Lower values
✔️ Earlier reactions
✔️ More frequent state changes
✔️ Higher sensitivity
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎨 Visual Features
The indicator includes several independent visualization options, each of which can be enabled or disabled separately.
✔️ Adaptive Trend Line
✔️ Glow Effect
✔️ Gradient Ribbon Between Price and Filter
✔️ Bullish / Bearish Transition Labels
✔️ Optional Candle Coloring
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔔 Alerts
Two alert conditions are available.
🟢 Bullish Trend State
🔴 Bearish Trend State
Alerts are triggered only when a new trend state is confirmed according to the selected confirmation mode.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 Typical Use
Trend State Signals is primarily designed as a market state filter rather than a complete trading system.
It can be used to:
✔️ Identify the dominant market direction
✔️ Filter signals generated by other trading strategies
✔️ Trade only in the direction of the prevailing trend
✔️ Reduce trades caused by short-term market noise
Like any trend-following methodology, the indicator confirms trend changes only after the market has moved a sufficient distance. As a result, signals may appear after the initial turning point. This is an intentional design choice that helps reduce the impact of random price fluctuations while improving trend stability.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Trading tools by MarketStructureLab. Professional indicators, algorithms & market structure logic. Get access: marketstructurelab.com
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Trading tools by MarketStructureLab. Professional indicators, algorithms & market structure logic. Get access: marketstructurelab.com
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.