Trend Age Counter
- 指标
- 版本: 1.0
- 激活: 5
# Trend Age Counter - Regime age versus typical duration
*Category: Trend | Difficulty: intermediate | Window: separate window below the chart | Markets: Universal (Forex, indices, commodities, crypto, stocks) | Suggested timeframes: M30, H1, H4, D1*
## Short description
> Counts how many bars the current regime has lasted and compares it with the average duration of all past regimes on the same instrument. It measures trend maturity, not strength.
### Overview
Every trend indicator answers how strong the move is. None answers how long it has lasted, yet that is information every experienced trader uses instinctively. Trend Age Counter makes it explicit. It defines the current regime in the simplest possible way, the position of price relative to a reference exponential average, and counts the bars since that regime began. At the same time it stores the duration of every regime that has ended on the same chart and computes their average, drawing it as a dashed line. The comparison between the two quantities is immediate: when the histogram exceeds the line, the running trend is already longer than trends normally last on this instrument and this timeframe.
### How the calculation works
1. An exponential average of period InpBaselinePeriod defines the dividing line between bullish and bearish regime.
2. The regime is plus one when price sits above the average, minus one when below; with price exactly on the average the previous regime is kept.
3. Age increases by one bar on every close confirming the regime and restarts from one when the regime changes.
4. When a regime ends its duration is added to the statistic, but only if it exceeds InpMinRunBars, so that spurious crossings do not distort the average.
5. The typical duration is the arithmetic mean of completed regimes and is shown only after at least three have been observed.
6. The sum and count of regimes are kept in calculation buffers, so recalculating a bar never alters the accumulated statistic.
### How to use it
- Treat a young trend, with the histogram well below the dashed line, as a context favourable to continuation entries.
- On a trend already beyond its typical duration do not stop trading, but tighten stops and cut size: the risk to reward ratio deteriorates.
- The histogram returning to one flags a regime change more clearly than a crossover, because it is visible even while price is still close to the average.
- Comparing the typical duration of one instrument across timeframes helps choose the operating horizon best suited to your style.
- Do not use it as a reversal signal: a trend can stay beyond its typical duration for a long time, and the most profitable trends are precisely the anomalous ones.
### Who it is for and on which timeframes
It targets traders holding positions for more than a few bars who must decide when to tighten management, hence mainly swing and position traders. The duration statistic becomes reliable only with enough completed regimes, so loading deep history is advisable: on H4 and D1 at least a couple of years of data are needed for a stable average. On intraday timeframes regimes follow one another quickly and the average forms sooner, but it is affected by differences between sessions.
### Practical example of reading a signal
On DAX40 D1 the typical regime duration settles around 18 bars. The running uptrend has reached an age of 41 bars: the green histogram is more than double the dashed line. This does not mean the advance must end, and indeed it continues for another nine sessions. It means this move is statistically exceptional for this market, and that anyone long for a while should switch to a tight trailing stop rather than add to the position. When price loses the reference average the histogram resets to one and changes colour, formally closing the regime, which enters the statistic as a new record duration.
## Input parameters
| Parameter | Default | Description |
|---|---|---|
| `InpBaselinePeriod` | 34 | Period of the average defining the regime. Short periods generate many brief regimes, long periods few very durable ones: the choice defines what counts as a trend. |
| `InpMinRunBars` | 3 | Minimum duration for a completed regime to enter the statistic. It excludes spurious crossings that would otherwise artificially lower the average duration. |
| `InpAppliedPrice` | PRICE_CLOSE | Price compared with the reference average. |
## Advantages / strengths
- It provides a market dimension, time, that virtually no commercial indicator measures.
- The reference is not an arbitrary parameter but the history of the instrument itself: it adapts automatically to markets with different personalities.
- It has an immediate use in position management, which is where most traders lose money.
- No repaint, no external dependency, only three parameters.
## Limitations and warnings
- The typical duration depends entirely on the chosen regime definition: changing InpBaselinePeriod changes the whole picture.
- On short histories the duration average is unstable and early values can be misleading.
- The arithmetic mean is heavily affected by exceptionally long regimes: on some instruments the median would be more representative.
- It says nothing about the strength or quality of the move: a young trend can be very weak and an old one still solid.
**No repaint:** values printed on a closed bar are never modified afterwards.
**Disclaimer.** This product is a technical analysis tool, not an automated trading system, and it offers no profit guarantee whatsoever. Financial markets carry the risk of total loss of the invested capital. Past performance is not indicative of future results. Every signal must be confirmed with your own analysis, a money management plan and prior testing on a demo account. The author is not responsible for trading decisions taken on the basis of this indicator.
## Suggested tags / keywords for MQL5
`trend`, `duration`, `regime`, `position management`, `statistics`, `maturity`, `no repaint`, `swing trading`
