Trend Duration Forecast [ChartPrime]⯁ OVERVIEW
The Trend Duration Forecast indicator is designed to estimate the probable lifespan of a bullish or bearish trend. Using a Hull Moving Average (HMA) to detect directional shifts, it tracks the duration of each historical trend and calculates an average to forecast how long the current trend is statistically likely to continue. This allows traders to visualize both real-time trend strength and potential exhaustion zones with exceptional clarity.
⯁ KEY FEATURES
Dynamic Trend Detection: Utilizes the Hull Moving Average to identify when price transitions into a new uptrend or downtrend.
Trend Duration Counting: Measures the number of bars in each completed bullish and bearish phase to understand trend persistence.
Forecast Projection: Automatically projects an estimated trend continuation line based on the average length of recent trends.
Real-Time Updates: Continuously updates the “Real Length” label as the trend develops.
Historical Data Table: Displays previous trend durations for both bullish and bearish cycles, along with their averages.
Adaptive Sampling: Uses a customizable sample size to smooth out volatility in the forecast and provide statistically meaningful projections.
Color-Based Clarity: Highlights uptrends in green and downtrends in orange for instant visual interpretation.
⯁ USAGE
Use the Trend Detection Sensitivity setting to control how fast or slow the indicator reacts to trend changes — lower values increase responsiveness, while higher values smooth out noise.
Compare the Real Length of the ongoing trend with the Probable Length forecast to estimate whether the move is nearing exhaustion.
Observe the historical duration table to understand the average lifespan of trends in the current market structure.
Use the color-coded HMA line and projection arrows to identify when momentum strength is fading and prepare for possible reversals.
Ideal for swing or trend-following strategies where trend longevity is crucial to managing entries and exits effectively.
⯁ CONCLUSION
The Trend Duration Forecast gives traders a quantitative edge by combining real-time trend tracking with statistical forecasting. It helps identify not only when a new trend begins, but also how long it’s likely to persist based on past market behavior. This indicator enhances timing precision for both entries and exits, supporting smarter trend-following decisions with clear, data-driven insights.
Duration
GenericTradingLibrary "GenericTrading"
This library aims to collect rare but useful operations for
get_most_recent_long_or_short_position_closed_index() : returns most recent long/short closed bar index.
get_most_recent_long_or_short_position_open_index() : returns most recent long/short closed bar index.
These two functions designed to help to speed up the coding for strategies that contains "re-enter" logic.
These two functions also could applies in the situations where time-count is needed in your condition.

