OPEN-SOURCE SCRIPT
Rolling Segment [LuxAlgo]

The Rolling Segment indicator provides a dynamic, trend-following reference line that adapts its slope and direction based on price volatility and distance from the market.
🔶 USAGE
The indicator is designed to filter out minor price fluctuations while remaining responsive to significant trend shifts. It appears as a continuous segmented line on the chart, changing color based on the current trend (Green for bullish, Red for bearish).
A gradient fill is applied between the price and the segment to visualize the "stretch" or deviation of the current price action from the trend line. This visual aid helps traders identify when price is moving in lockstep with the trend versus when it is overextending.
🔹 Reversal Signals
The indicator identifies trend reversals when the distance between the price and the segment exceeds a user-defined ATR-based threshold. These reversals are marked on the chart with triangle labels:
🔹 Speed Modes
The segment operates in two speed modes: "Fast" and "Slow." When price moves significantly away from the segment (crossing the Fast Threshold), the indicator switches to a faster slope to catch up with the momentum. When price is closer to the segment, it maintains a slower, more stable slope to avoid premature trend changes during consolidation.
🔶 MARKET INTERPRETATION
The Rolling Segment acts as a measure of trend health. Because the slope is derived from the Average True Range (ATR), the "speed" of the line is normalized to the asset's current volatility.
🔶 DETAILS
The core of the script relies on a state-machine logic that governs a unique slope-freezing mechanism. Unlike traditional moving averages that recalculate every bar based on shifting data, this indicator calculates a linear slope and "freezes" it until a specific state change occurs.
The state is defined by the combination of Trend Direction and Speed Mode. The ATR value used to calculate the slope is only updated when:
By freezing the slope, the indicator produces perfectly linear segments. This mathematical intuition ensures that the reference line moves at a constant "volatility-adjusted rate" per bar, providing a cleaner visual representation of trend momentum and making it easier to spot price exhaustion when the market deviates too far from this constant rate.
🔶 SETTINGS
🔹 Slopes
🔹 ATR Settings
🔹 Thresholds
🔶 USAGE
The indicator is designed to filter out minor price fluctuations while remaining responsive to significant trend shifts. It appears as a continuous segmented line on the chart, changing color based on the current trend (Green for bullish, Red for bearish).
A gradient fill is applied between the price and the segment to visualize the "stretch" or deviation of the current price action from the trend line. This visual aid helps traders identify when price is moving in lockstep with the trend versus when it is overextending.
🔹 Reversal Signals
The indicator identifies trend reversals when the distance between the price and the segment exceeds a user-defined ATR-based threshold. These reversals are marked on the chart with triangle labels:
- A bullish triangle (▲) appears below the segment when a new uptrend begins.
- A bearish triangle (▼) appears above the segment when a new downtrend begins.
🔹 Speed Modes
The segment operates in two speed modes: "Fast" and "Slow." When price moves significantly away from the segment (crossing the Fast Threshold), the indicator switches to a faster slope to catch up with the momentum. When price is closer to the segment, it maintains a slower, more stable slope to avoid premature trend changes during consolidation.
🔶 MARKET INTERPRETATION
The Rolling Segment acts as a measure of trend health. Because the slope is derived from the Average True Range (ATR), the "speed" of the line is normalized to the asset's current volatility.
- Trend Momentum: When the price stays consistently above a green segment (or below a red one) without triggering the "Fast" mode, it indicates a stable, sustainable trend.
- Price Exhaustion: A sudden jump into "Fast" mode often highlights a surge in momentum. If the price continues to stretch significantly beyond the segment even in fast mode, it may signal an overextended move prone to mean reversion.
- Consolidation: Horizontal or shallow segments indicate a period where the market is lacking a clear directional driver relative to its recent volatility.
🔶 DETAILS
The core of the script relies on a state-machine logic that governs a unique slope-freezing mechanism. Unlike traditional moving averages that recalculate every bar based on shifting data, this indicator calculates a linear slope and "freezes" it until a specific state change occurs.
The state is defined by the combination of Trend Direction and Speed Mode. The ATR value used to calculate the slope is only updated when:
- A trend reversal is detected (Price crosses the Reverse Threshold).
- The distance between price and the segment crosses the "Fast Threshold," triggering a shift in speed mode.
- The initial calculation begins at the start of the data series.
By freezing the slope, the indicator produces perfectly linear segments. This mathematical intuition ensures that the reference line moves at a constant "volatility-adjusted rate" per bar, providing a cleaner visual representation of trend momentum and making it easier to spot price exhaustion when the market deviates too far from this constant rate.
🔶 SETTINGS
🔹 Slopes
- Fast Slope Length: The period used to determine the slope speed when the price is trending strongly. Lower values result in a steeper, more aggressive slope.
- Slow Slope Length: The period used to determine the slope speed during standard market conditions. Higher values create a flatter, more trailing segment.
🔹 ATR Settings
- ATR Length: The lookback period for the Average True Range calculation, which scales the slope and thresholds to current market volatility.
🔹 Thresholds
- Fast Slope Threshold (ATR Multiplier): The distance (in ATR units) the price must reach from the segment to trigger the "Fast" slope mode.
- Reverse Threshold (ATR Multiplier): The distance (in ATR units) the price must cross against the current trend to trigger a reversal and change the segment direction.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.