OPEN-SOURCE SCRIPT
Cập nhật Trend Structure & Untested Levels

Trend Structure & Tested Levels
Draws the swing trend as a zigzag, turns every swing into a support/resistance level, and tracks whether price has closed through it ("tested") or not ("untested").
Overview
A market-structure tool. It connects confirmed swing highs and lows into a clean zigzag trend line, then projects a horizontal level from each swing. Every level is classified by state — untested until a candle closes through it, after which the most recent break in each direction is flagged as Last Gained or Last Lost. The result is an at-a-glance map of the active structure and which levels are still in play.
What it does
Swing trend (zigzag). Connects confirmed pivot highs/lows into a trend line. A live, provisional leg always runs from the last confirmed pivot to the current price, so the structure reaches the current bar.
Automatic levels. Each swing high/low becomes a horizontal level — highs above price act as resistance, lows below price as support.
Tested vs untested. A level stays untested until a candle closes through it; a wick touch alone does not count.
Last Gained / Last Lost. The most recent resistance price closed above is tagged Last Gained (bullish break of structure); the most recent support price closed below is tagged Last Lost (bearish break).
Multi-timeframe
Levels — and the zigzag, in follow mode — can be drawn from the chart timeframe or any higher timeframe (e.g. D / W / M), labelled with a suffix such as (W). Higher-timeframe pivots are read without repainting forward-filled values and are anchored at the real pivot time, so an HTF level sits where it actually formed and runs horizontally across the whole chart.
Key settings
Pivot length — the master sensitivity control. Lower = a finer zigzag and more, smaller levels; higher = only the major structure.
Swing source — wicks (high/low) or candle bodies (open/close) to ignore wick spikes.
Zigzag follows levels timeframe — keep trend line and levels on one structure, or decouple the zigzag onto the chart timeframe.
Independent colours, line styles, widths, and a per-side cap on untested levels.
Notes
This is a visualisation of structure, not a signal or strategy — it says nothing about profitability; validate separately.
Repainting. Swings confirm pivot length bars after the fact, and the live leg moves with price until a new pivot confirms.
Not financial advice.
Draws the swing trend as a zigzag, turns every swing into a support/resistance level, and tracks whether price has closed through it ("tested") or not ("untested").
Overview
A market-structure tool. It connects confirmed swing highs and lows into a clean zigzag trend line, then projects a horizontal level from each swing. Every level is classified by state — untested until a candle closes through it, after which the most recent break in each direction is flagged as Last Gained or Last Lost. The result is an at-a-glance map of the active structure and which levels are still in play.
What it does
Swing trend (zigzag). Connects confirmed pivot highs/lows into a trend line. A live, provisional leg always runs from the last confirmed pivot to the current price, so the structure reaches the current bar.
Automatic levels. Each swing high/low becomes a horizontal level — highs above price act as resistance, lows below price as support.
Tested vs untested. A level stays untested until a candle closes through it; a wick touch alone does not count.
Last Gained / Last Lost. The most recent resistance price closed above is tagged Last Gained (bullish break of structure); the most recent support price closed below is tagged Last Lost (bearish break).
Multi-timeframe
Levels — and the zigzag, in follow mode — can be drawn from the chart timeframe or any higher timeframe (e.g. D / W / M), labelled with a suffix such as (W). Higher-timeframe pivots are read without repainting forward-filled values and are anchored at the real pivot time, so an HTF level sits where it actually formed and runs horizontally across the whole chart.
Key settings
Pivot length — the master sensitivity control. Lower = a finer zigzag and more, smaller levels; higher = only the major structure.
Swing source — wicks (high/low) or candle bodies (open/close) to ignore wick spikes.
Zigzag follows levels timeframe — keep trend line and levels on one structure, or decouple the zigzag onto the chart timeframe.
Independent colours, line styles, widths, and a per-side cap on untested levels.
Notes
This is a visualisation of structure, not a signal or strategy — it says nothing about profitability; validate separately.
Repainting. Swings confirm pivot length bars after the fact, and the live leg moves with price until a new pivot confirms.
Not financial advice.
Phát hành các Ghi chú
Bug Fixes Phát hành các Ghi chú
Better trend detection. Use Pivot length option to change sensitivityPhát hành các Ghi chú
english settings Phát hành các Ghi chú
Alerts on gained and lost levels Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.