OPEN-SOURCE SCRIPT

TIS_Swing

764
OVERVIEW

TIS_Swing detects swing highs and swing lows and, unlike most pivot tools, publishes the last confirmed level as a continuous value that other scripts can read.

Standard pivot indicators return a number only on the bar where the pivot is confirmed and nothing on every other bar. That is fine for drawing a dot on the chart, but it makes the level unusable for comparison: on any given bar you cannot ask whether the current price is above the last confirmed swing high, because on that bar the pivot series holds no value. TIS_Swing keeps the level alive between pivots, so that question can be answered on every bar, by you visually or by another script through the source dropdown.


HOW IT WORKS

A bar qualifies as a swing high when its high is greater than or equal to the highs of the bars that follow it, and strictly greater than the highs of the bars that precede it. The number of bars checked on each side is set by Strength Left and Strength Right. Swing lows use the mirrored rule. The comparison on the right side is inclusive, so a candidate that ties with a later bar still qualifies; this produces slightly more pivots than a strictly greater definition, and is intentional.

A pivot can only be confirmed once the bars to its right exist, so a pivot is always confirmed Strength Right bars after it forms. It is never confirmed earlier and it is never revised afterwards, so nothing repaints.

Once a pivot is confirmed, its price becomes the current level for that side and stays there until the next pivot on the same side replaces it. When the series trades through the level, the level is marked as broken. What happens next depends on Remove Broken Pivot Lines:

- ON, the default: the visible level is dropped and no level is shown until a new pivot forms. This is the familiar behaviour of most pivot tools.
- OFF: the visible level stays where it was until a new pivot replaces it, so a broken level remains on screen as a reference.

Either way, a second pair of values keeps the last level regardless of the setting. Those are the plots marked (persistent), and they exist so that comparisons are always possible.


WHAT YOU CAN DO WITH IT

Market structure on price. With the level available on every bar, a higher high is simply the current price trading above the last confirmed swing high, and a lower low is the mirror. You can read it off the chart or compute it in your own script by selecting Last Swing High (persistent) as a source and comparing it against the close.

Divergence on an oscillator. Turn on Use Other Source, point it at a stochastic, an RSI or any other plotted series, and move the script to its own pane. The pivots are then detected on the oscillator instead of on price. A higher swing low on the oscillator while price is still making lower lows is a classic divergence, and here it is visible as a stepped level moving up while price moves down.

Breakout timing. With Remove Broken Pivot Lines on, the moment the level disappears is the moment the last swing was taken out. That transition is also available as an alert.


PARAMETERS

Parameters
- Strength Left: bars to the left of the candidate that must be lower for a high, or higher for a low. Default 5.
- Strength Right: bars to the right required to confirm the pivot. Also the confirmation delay, in bars. Default 2.
- Remove Broken Pivot Lines: drop the visible level once it is broken. Default on. Does not affect the (persistent) plots.
- Use Other Source: detect pivots on another plotted series instead of the bar highs and lows. Both sides then use the selected series.
- Source: the series used when Use Other Source is on.

Visual Settings
- Show Levels: opacity of the stepped level lines.
- Show Persistent Levels: opacity of the thin lines that always keep the last level. Off by default to keep the chart clean.
- Show Pivot Markers: diamonds drawn on the confirmed pivot bars.
- Extend to the Right: horizontal line projected forward from the last pivot on each side.
- Swing High Color, Swing Low Color, Line Width, Extension Line Style.

The Show options change opacity only. The four series are always published, so another script can read them even when they are not visible on the chart.


OUTPUTS

Four values are available in the source dropdown of any other indicator or strategy:

- Last Swing High and Last Swing Low: the level as shown, honouring Remove Broken Pivot Lines.
- Last Swing High (persistent) and Last Swing Low (persistent): the last confirmed level, kept regardless of that setting.

Four alerts are available: New Swing High, New Swing Low, Swing High Broken, Swing Low Broken.


LIMITATIONS

- A pivot is confirmed Strength Right bars after the bar that forms it. On the chart this looks like a delay, and it is one. It is inherent to any pivot definition that requires confirmation from the right, and it is the price of not repainting.
- These levels are reference points, not entry signals. Nothing here tells you which way to trade.
- With Remove Broken Pivot Lines on, the level is dropped on the same bar as the break. A comparison such as close above Last Swing High will therefore never be true, because the value is already gone by the time it would be. Use the (persistent) plots for that comparison, or detect the break as the transition of the visible plot to no value.
- Before the first pivot on a side is confirmed, that side publishes no value.
- Pine fixes the pane at compile time, so with a non-price source the script has to be moved to its own pane manually.
- Larger Strength values give fewer and more significant levels but a longer confirmation delay. There is no setting that avoids that trade-off.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.