OPEN-SOURCE SCRIPT
Trend Age Map

Trend Age Map is a visual trend-segmentation and historical-context indicator.
Instead of displaying only the current market direction, the script divides the chart into completed and active uptrend and downtrend segments. Each segment is measured by its duration in bars and its percentage magnitude, allowing the current trend to be viewed in the context of previous trends from the same chart.
HOW IT WORKS
During an uptrend, the script tracks the highest price reached by the active segment. The uptrend ends when the closing price retraces from that extreme by the selected reversal distance.
During a downtrend, the script tracks the lowest price reached by the active segment. The downtrend ends when the closing price rises from that extreme by the selected reversal distance.
When a reversal is confirmed, the completed trend is stored as a historical sample and a new segment begins from the previous trend's extreme.
REVERSAL MODES
1. Adaptive ATR
This is the default mode.
The reversal distance is calculated from ATR on the active chart timeframe. Because each timeframe uses its own bars and volatility, changing from a daily chart to an hourly or minute chart recalculates the trend structure for that timeframe.
Three adaptive sensitivity settings are available:
- Fast: uses 2.0 x ATR and produces more frequent, shorter segments.
- Balanced: uses 3.5 x ATR and provides a middle-ground structure.
- Slow: uses 5.0 x ATR and retains only larger trend movements.
2. Percent
The reversal distance is a fixed percentage of the latest trend extreme.
Because the percentage is independent of timeframe volatility, the same major trend structure may remain visible across several timeframes.
3. ATR
This mode allows the user to select a manual ATR multiplier.
TREND BOXES
Completed uptrends are displayed with teal boxes.
Completed downtrends are displayed with red boxes.
The vertical range of each completed box represents the movement from the segment's starting price to its final extreme. Its horizontal width represents the segment's duration.
The active trend is displayed as a provisional box with a dashed border. This box continues to extend and update until a qualifying reversal is confirmed.
Historical duration and percentage labels are optional and disabled by default to keep lower-timeframe charts clean.
HISTORICAL CONTEXT
The script maintains separate historical samples for completed uptrends and downtrends.
For the active trend, it calculates:
- Current direction.
- Current age in bars.
- Current percentage magnitude.
- Age percentile relative to previous trends in the same direction.
- Magnitude percentile relative to previous trends in the same direction.
- Number of comparable completed trends.
- Effective ATR multiplier when an ATR-based mode is active.
These values are available in the Data Window and are not displayed as an information box on the chart.
The percentile values describe where the current trend ranks within the loaded chart history. They are descriptive comparisons, not probabilities that the trend will continue or reverse.
USER CONTROLS
The script includes controls for:
- Reversal calculation mode.
- Adaptive sensitivity.
- Manual percentage or ATR threshold.
- ATR calculation length.
- Minimum trend duration.
- Reversal confirmation on candle close.
- Historical and current trend-box visibility.
- Optional duration and magnitude labels.
- Maximum number of retained drawings.
- Maximum number of retained statistical samples.
- Box transparency.
- Uptrend and downtrend colors.
LOW-TIMEFRAME HANDLING
Drawings use time-based coordinates so the indicator can operate across long intraday datasets without relying on distant bar-index coordinates.
The number of historical drawings and statistical samples is capped. When a selected limit is exceeded, the oldest retained item is removed. Lower drawing limits may improve chart performance on small timeframes.
ALERTS
Alert conditions are available when:
- A new uptrend segment is confirmed.
- A new downtrend segment is confirmed.
When candle-close confirmation is enabled, these events are confirmed only after the active bar closes.
REPAINTING AND BEHAVIOR
The current trend box is provisional by design. It changes as the active trend extends, forms a new extreme, or eventually reverses.
With "Confirm reversals on candle close" enabled, a trend-direction change is accepted only after the candle closes.
After a reversal is confirmed, the completed trend box is no longer modified during normal chart operation.
Changing the symbol, timeframe, historical dataset, reversal mode, sensitivity, or other calculation settings causes the indicator to recalculate its historical segmentation.
If candle-close confirmation is disabled, the current trend state can change while the realtime candle is forming.
The first trend begins from the first available bar in the loaded dataset, so its starting point should be considered approximate.
LIMITATIONS
Trend segmentation depends on the selected reversal threshold. A faster setting creates more segments and reacts to smaller movements, while a slower setting retains broader movements.
ATR-based calculations adapt to the volatility of the active timeframe, so structures are not expected to remain identical when the timeframe changes.
The displayed history is limited by the selected maximum drawing and sample settings.
Percentile readings depend entirely on the completed trends available in the loaded chart dataset. They do not represent universal market statistics.
Trend Age Map is a descriptive visual-analysis tool. It does not predict when a trend will end, does not place orders, and should not be interpreted as a standalone buy or sell system.
Instead of displaying only the current market direction, the script divides the chart into completed and active uptrend and downtrend segments. Each segment is measured by its duration in bars and its percentage magnitude, allowing the current trend to be viewed in the context of previous trends from the same chart.
HOW IT WORKS
During an uptrend, the script tracks the highest price reached by the active segment. The uptrend ends when the closing price retraces from that extreme by the selected reversal distance.
During a downtrend, the script tracks the lowest price reached by the active segment. The downtrend ends when the closing price rises from that extreme by the selected reversal distance.
When a reversal is confirmed, the completed trend is stored as a historical sample and a new segment begins from the previous trend's extreme.
REVERSAL MODES
1. Adaptive ATR
This is the default mode.
The reversal distance is calculated from ATR on the active chart timeframe. Because each timeframe uses its own bars and volatility, changing from a daily chart to an hourly or minute chart recalculates the trend structure for that timeframe.
Three adaptive sensitivity settings are available:
- Fast: uses 2.0 x ATR and produces more frequent, shorter segments.
- Balanced: uses 3.5 x ATR and provides a middle-ground structure.
- Slow: uses 5.0 x ATR and retains only larger trend movements.
2. Percent
The reversal distance is a fixed percentage of the latest trend extreme.
Because the percentage is independent of timeframe volatility, the same major trend structure may remain visible across several timeframes.
3. ATR
This mode allows the user to select a manual ATR multiplier.
TREND BOXES
Completed uptrends are displayed with teal boxes.
Completed downtrends are displayed with red boxes.
The vertical range of each completed box represents the movement from the segment's starting price to its final extreme. Its horizontal width represents the segment's duration.
The active trend is displayed as a provisional box with a dashed border. This box continues to extend and update until a qualifying reversal is confirmed.
Historical duration and percentage labels are optional and disabled by default to keep lower-timeframe charts clean.
HISTORICAL CONTEXT
The script maintains separate historical samples for completed uptrends and downtrends.
For the active trend, it calculates:
- Current direction.
- Current age in bars.
- Current percentage magnitude.
- Age percentile relative to previous trends in the same direction.
- Magnitude percentile relative to previous trends in the same direction.
- Number of comparable completed trends.
- Effective ATR multiplier when an ATR-based mode is active.
These values are available in the Data Window and are not displayed as an information box on the chart.
The percentile values describe where the current trend ranks within the loaded chart history. They are descriptive comparisons, not probabilities that the trend will continue or reverse.
USER CONTROLS
The script includes controls for:
- Reversal calculation mode.
- Adaptive sensitivity.
- Manual percentage or ATR threshold.
- ATR calculation length.
- Minimum trend duration.
- Reversal confirmation on candle close.
- Historical and current trend-box visibility.
- Optional duration and magnitude labels.
- Maximum number of retained drawings.
- Maximum number of retained statistical samples.
- Box transparency.
- Uptrend and downtrend colors.
LOW-TIMEFRAME HANDLING
Drawings use time-based coordinates so the indicator can operate across long intraday datasets without relying on distant bar-index coordinates.
The number of historical drawings and statistical samples is capped. When a selected limit is exceeded, the oldest retained item is removed. Lower drawing limits may improve chart performance on small timeframes.
ALERTS
Alert conditions are available when:
- A new uptrend segment is confirmed.
- A new downtrend segment is confirmed.
When candle-close confirmation is enabled, these events are confirmed only after the active bar closes.
REPAINTING AND BEHAVIOR
The current trend box is provisional by design. It changes as the active trend extends, forms a new extreme, or eventually reverses.
With "Confirm reversals on candle close" enabled, a trend-direction change is accepted only after the candle closes.
After a reversal is confirmed, the completed trend box is no longer modified during normal chart operation.
Changing the symbol, timeframe, historical dataset, reversal mode, sensitivity, or other calculation settings causes the indicator to recalculate its historical segmentation.
If candle-close confirmation is disabled, the current trend state can change while the realtime candle is forming.
The first trend begins from the first available bar in the loaded dataset, so its starting point should be considered approximate.
LIMITATIONS
Trend segmentation depends on the selected reversal threshold. A faster setting creates more segments and reacts to smaller movements, while a slower setting retains broader movements.
ATR-based calculations adapt to the volatility of the active timeframe, so structures are not expected to remain identical when the timeframe changes.
The displayed history is limited by the selected maximum drawing and sample settings.
Percentile readings depend entirely on the completed trends available in the loaded chart dataset. They do not represent universal market statistics.
Trend Age Map is a descriptive visual-analysis tool. It does not predict when a trend will end, does not place orders, and should not be interpreted as a standalone buy or sell system.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.