OPEN-SOURCE SCRIPT

EMA Stack Auto Trendlines

14
Most auto-trendline tools find their swing points with fractals — a high with N lower highs either side of it. This one finds them with EMA structure instead.

How swings are identified

Six EMAs are tracked: 5, 12, 34, 50, 72 and 89, calculated on hl2 by default. The script cares about one thing — whether they are perfectly stacked:

Bullish: 5 > 12 > 34 > 50 > 72 > 89
Bearish: 5 < 12 < 34 < 50 < 72 < 89

While the market is in a bullish swing, every candle high is tracked and the highest one is held as the running extreme. The swing only ends when the complete bearish stack appears and holds for a set number of consecutive bars — at which point the tracked high becomes a confirmed swing high. Bearish swings work the same way in reverse, tracking lows.

Partial EMA disorder does nothing. The stack has to fully invert, and stay inverted, before a swing changes direction. That's what keeps normal pullbacks inside a trend from fragmenting it into dozens of minor pivots.

Trendlines

Confirmed highs are connected high-to-high, confirmed lows low-to-low. The most recent line on each side is drawn in its own style and can extend right as a forward projection; older lines drop back to a dimmer historic style, with a configurable number retained.

A dotted forming line runs from the last confirmed pivot to the extreme of the swing currently in progress, so the projection is visible before the opposite stack arrives to confirm it. It moves as new extremes print — by design, since the swing hasn't finished yet. Confirmed lines never move once drawn.

Swing filter

A full stack reversal on its own isn't enough. Each candidate pivot is measured against the last confirmed pivot in the opposite direction and must clear a minimum distance, set in ATR multiples or percent.

If it fails, the swing doesn't end — it keeps running and keeps tracking the same extreme, so a shallow counter-move leaves no pivot on either side of it. A release valve accepts the pivot anyway once price has travelled a full swing distance out of the tracked extreme, which prevents the state from locking in one direction. Set the filter to Off if you want every stack reversal to count.

Settings worth tuning first

Minimum Swing Measured In — Percent tends to travel better across timeframes than ATR, since the same ATR multiple means very different things on 5m and 1h.
Confirmation Bars — how long the opposite stack must hold. Raise it on noisy intraday charts.
Show Swing Points — turn this on while tuning. Get the H and L labels landing where you'd mark them by hand, then worry about the lines.

Alerts fire on each newly confirmed swing high and swing low.

The EMA lengths follow the pairings popularised by Ripster's EMA Clouds. No code from that script is used here — only the choice of lengths.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。