OPEN-SOURCE SCRIPT
EMA Stack Auto Trendlines

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.
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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.