OPEN-SOURCE SCRIPT

Leg Anatomy - Measured Retracement and Extension

3 736
Every trader draws the same three numbers on every chart: 38.2, 50 and 61.8. Those numbers were not derived from this market, this timeframe, or this instrument. They were not derived from any market. They are a convention that spread because it spread.

This script measures the real thing instead.

WHAT IT MEASURES

Price is broken into confirmed swing legs. A running extreme is tracked, and when price closes back from that extreme by more than a configurable multiple of ATR, the extreme is confirmed as a swing and a new leg begins.

Every completed leg is measured as a ratio of the leg immediately before it. A leg that travelled 60 percent of the previous leg records 0.60. A leg that went 140 percent past it records 1.40. That single number, the leg-to-leg ratio, is the entire dataset.

From the last N legs on the chart you have open, the panel reports:

The median leg, expressed as a multiple of the one before it.
The interquartile range, the middle half of the distribution.
The share of legs that were shallow, under 0.62.
The share that were deep, between 0.62 and 1.00.
The share that were extensions, past 1.00.

On some symbols and timeframes the conventional levels sit close to the measured centre. On many they do not, and the gap between what a chart actually does and what the convention assumes is visible in one row of the panel.

THE PROJECTION

The distribution is not left as a table. It is applied forward.

The leg currently forming starts from the last confirmed swing, and the leg before it has a known size. Multiplying that size by the measured median, upper quartile and ninetieth percentile gives three projected endpoints, drawn as a shaded zone in front of price with a dashed median line and a price label.

The panel shows how far the forming leg has travelled as a percentage of its median expectation. Below 100 percent the leg is still inside its normal range. Above it, the leg has already outrun the typical case for this chart, which is information whether you are holding it or fading it.

The zone is not a forecast. It is where the middle of the distribution sits, and roughly half of past legs fell short of it.

THE SKELETON

Confirmed legs are drawn as a thick zigzag across the chart, each one labelled with its own ratio, so the distribution in the panel can be read directly off the price action that produced it. Candles are tinted by the direction of the leg currently forming.

Because swings only confirm on closed bars and a confirmed swing is never revisited, the skeleton behind price is final. Only the leg at the right edge is still forming, and the projection zone updates only when a new leg is confirmed.

SETUPS

When a swing confirms, a new leg begins, and the script produces a complete setup at that close.

The stop sits just beyond the swing that was just confirmed, plus an ATR buffer. That swing is the level the leg depends on. If it goes, the leg reading was wrong.

The three targets are the lower quartile, the median and the upper quartile of the measured distribution, projected from the swing. They are not multiples of risk and they are not conventional ratios. They are the shape of this chart's own legs.

Only one setup is tracked at a time. The panel records whether the first target or the stop was reached first, and prints collecting until the sample is large enough to mean anything. That number measures one mechanical rule and is not a backtest.

SETTINGS

Reversal Threshold is the only structural dial. It decides what counts as a leg. A low value produces many small legs and a distribution dominated by noise. A high value produces few large legs and a distribution with a small sample. The default sits between the two, and changing it changes the entire analysis, which is the point: a leg on a scalping horizon is not a leg on a swing horizon, and the measured distribution should differ between them.

Volatility Length sets the ATR lookback used for the reversal threshold and the stop buffer.

Legs Kept In Sample bounds the history, so the distribution tracks the current regime instead of averaging in a market from years ago.

REPAINTING

Swing confirmation, leg measurement, the distribution, setups and alerts all evaluate on confirmed bars. A confirmed swing is never moved and a drawn leg is never redrawn. The projection zone in front of price is recomputed only when a new leg begins. The script requests no higher timeframe data.

HOW TO READ IT

Start with the three share rows. If a chart shows most of its legs under 0.62, it is a market that retraces shallowly and continuation is the base case. If most legs sit between 0.62 and 1.00, it is a market that gives deep pullbacks and entering early is expensive. A high share above 1.00 is a trending regime where each leg outruns the last.

Then look at the forming leg's progress. A leg at 40 percent of median with a distribution that favours extension is a different situation from a leg at 130 percent in a market that rarely extends.

The ratios printed on the skeleton let you check the panel against your own eyes rather than trusting it.

This is an analysis tool, not financial advice, and not a trading system. A measured distribution describes what happened, not what will. Sample sizes are small by the standards of statistics and regimes change. Use it with your own risk management and position sizing.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。