Aktualisiert

Trend Leg Maturity (ATR ZigZag)

2 997
█ Overview

Is this trend move still young, or already stretched?

Trend Leg Maturity answers that with facts from your own chart. It tracks every trend leg with an ATR-based ZigZag, then ranks the current leg's age (in bars) and size (in ATR) against up to 100 completed legs in the same direction on the same symbol and timeframe. The result is a simple maturity label (YOUNG, MID-LIFE or MATURE), a four-line panel, and a shaded zone that shows how close price is to confirming the leg over.

Snapshot

What you get at a glance:
  • A percentile rank for trend age: "older than 72% of past legs".
  • A percentile rank for trend extension: "bigger than 64% of past legs".
  • A maturity label that combines the two.
  • A pullback meter with the exact level where a close would confirm the leg over.
  • A leg line coloured by maturity, plus a translucent zone from the peak to that level.
  • Three alerts: up leg over, down leg over, leg became MATURE.


Why it is different: most "overextended" tools use one fixed threshold (for example an oscillator above 70) that means different things on different symbols and timeframes. Here the yardstick is the chart's own swing history, so "stretched" is measured against what moves on this very chart have actually done. It also shows the confirmation level and how much of the way price has already pulled back, using only closed-bar information, so past legs never change.

It is a descriptive context tool. It does not predict reversals or continuations, and it does not tell you what to do. Free and open-source.

▌ Leg lines and zone on the chart
The current leg is a line from its start pivot to its current peak, coloured by maturity: teal = YOUNG, blue = MID-LIFE, amber = MATURE, grey while the chart is still building history. A translucent zone with a dashed edge spans from the peak to the "leg ends" level, so you can see how much room is left before the leg would be confirmed over. The last six completed legs remain as thin grey lines. The first partial leg after the chart loads is not drawn.

Snapshot

▌ Panel
Four short rows. Hover any cell for details.
  • Title: the leg direction and its maturity class (or how many past legs have been collected so far).
  • Age: a ten-circle meter, the leg's age in bars, and how many past legs it is older than.
  • Stretch: a ten-circle meter, the leg's size in ATR, and how many past legs it is bigger than.
  • Leg ends: a ten-circle meter showing how much of the reversal threshold price has already pulled back from the peak, and the confirmation level (down arrow for an up leg, up arrow for a down leg). The meter turns amber from 50% and red from 80%.


█ How It Works

Key concepts and attribution: ATR-based ZigZag (reversal-threshold) swing detection and percentile ranking are established methods. This script is independently written and combines them for one purpose: ranking the current leg against the chart's own completed legs.

  1. Volatility unit: ATR (default length 14) at each confirmed bar.
  2. Legs:
    • An up leg tracks its highest high since its start; a down leg tracks its lowest low.
    • An up leg is confirmed over when a bar closes at or below its peak minus the reversal threshold times ATR (default 2.5).
    • A down leg is confirmed over when a bar closes at or above its low plus the same amount.
  3. New leg:
    • When a leg is confirmed over, the opposite leg starts at the old peak (the pivot). It takes the lowest low (or highest high) since that pivot as its current extreme.
    • A pivot is recognised only after price has retraced by the reversal threshold. Once recognised, it never moves.
    • The first partial leg after loading is ignored.
  4. Current leg measures:
    • Age = bars from the pivot to the current bar.
    • Stretch = distance from the pivot to the current peak, divided by the current ATR.
  5. History: for each direction the script keeps up to the 100 most recent completed legs. For each one it stores the lifetime in bars (pivot to the bar that confirmed the reversal) and the size in ATR at confirmation.
  6. Percentile rank:
    • The share of stored legs in the same direction that are smaller than the current value (ties count half).
    • Percentiles appear once at least 10 past legs exist in that direction.
    • The meter shows the percentile rounded to the nearest tenth (each filled circle is about 10%).
  7. Maturity score:
    • The average of the age percentile and the stretch percentile.
    • Below 33.3 is YOUNG, above 66.7 is MATURE, otherwise MID-LIFE.
    • The equal weights and the 33/67 cut-offs are simple defaults, not tuned.
    • The label describes where the leg ranks; it is not a probability.
  8. Leg-ends level:
    • The peak minus (up leg) or plus (down leg) the reversal threshold times the current ATR.
    • The Leg ends meter fills as price pulls back from the peak: filled share = pullback from the peak divided by the reversal threshold, capped at 100%.
    • The level moves with each new peak and with ATR.


Timing: legs, history, maturity, lines, zone and alerts update on confirmed bars only. The panel's pullback meter uses the live close and may change until the bar closes.

█ How to Use

This indicator supplies context and levels. It does not make or recommend trading decisions. Your own method and risk rules do. Questions the panel helps you answer:
  • Which way is the current leg, and how long has it lasted compared with legs on this chart? (Age.)
  • How far has it moved compared with past legs? (Stretch.)
  • Is the leg young, mid-life or mature by both measures combined? (Title.)
  • Where would a close confirm that the leg is over, and how much of the way has price already pulled back? (Leg ends meter and zone. Hover for the distance in pips or points.)
  • Did the leg just become MATURE? (Alert.)

Maturity is context. In the author's exploratory tests, older and more stretched legs continued only slightly less often than young ones (a few percentage points, not statistically verified), so a MATURE leg is not a reversal signal and a YOUNG leg is not a continuation signal.

Compare several timeframes. Works on crypto, forex, indices and stocks with standard candles; Heikin Ashi, Renko and similar types change the OHLC values the logic relies on.

█ Settings

Core Logic
  • Reversal threshold x ATR (default 2.5): how far a close must retrace from a leg's peak to confirm it over. Lower = more, shorter legs; higher = fewer, longer legs.
  • ATR length (default 14).
  • Past legs kept per direction (default 100).
  • Minimum past legs for percentiles (default 10).


Display
  • Draw legs (default on), Draw "leg ends" zone (default on), Show panel (default on), Panel position (default Top Right), Panel text size (default Small).


█ Alerts

Three conditions, all evaluated on confirmed bars only (choose "Once Per Bar Close"):
  1. Up leg confirmed over: a bar closed at or below the peak minus the threshold; a down leg starts.
  2. Down leg confirmed over: a bar closed at or above the low plus the threshold; an up leg starts.
  3. Leg became MATURE: the current leg's maturity class changed to MATURE on this bar (fires once per leg).

Alerts track only the current leg. They do not fire on unfinished bars.

█ Limitations

  • Pivots are recognised late: a leg's start (the previous peak) is known only after price has retraced by the reversal threshold. It does not move afterwards, but you do not see it in real time.
  • The current leg's peak can still extend, so its Age, Stretch, maturity and zone change until the leg is confirmed over.
  • Percentiles compare a leg only with past legs on the same chart and direction. They are not comparable across symbols or timeframes, and they change when more history loads.
  • Legs depend on the reversal threshold. In ranging markets legs are small and short, so percentiles describe small moves.
  • Exploratory research by the author on about 5,000 bars each of BTCUSDT (1h and 4h), EURUSD, GBPUSD and SPX500 (1h): a prototype "probability the leg continues" taken from past legs was overconfident (it predicted 73-86%; about 60-67% occurred), so it is not shown here. Older and more stretched legs continued a few percentage points less often, which is small and unverified. Maturity is context, not a prediction.
  • With fewer than the minimum past legs, only raw Age and Stretch are shown.
  • The "leg ends" level uses the current ATR and is not a trading level by itself.
  • Gaps, thin liquidity and data differences between exchanges or feeds can change legs.


█ Disclaimer

This indicator is an analytical and educational tool. It is not financial advice, a recommendation or a signal to buy or sell, and it does not guarantee future results. Trading involves risk of loss. You are responsible for your own trading decisions.
Versionshinweise
  • UI optimizations
Versionshinweise
*Draw legs (default on), Past legs shown (default 8; 0 hides them), Glow behind current leg (default on), Draw "leg ends" zone (default on), Draw leg label (default on), Leg label size (default Small; Tiny, Small, Normal, Large or Huge, for the label on the current leg's peak), Show panel (default on), Panel position (default Top Right), Panel text size (default Small).

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.