OPEN-SOURCE SCRIPT
Actualizado

Swing High/Low Extensions

227
Swing High/Low — Extensions (2 Plots + Drawings + Touch Signal)

What it does

This indicator finds Swing Highs/Lows using a symmetric length (same bars left & right), then creates horizontal extension levels that run to the right and stop at the first price touch (“extend until future intersection”).
It outputs:

Two plots showing the most recent active High/Low extension (great for alerts & strategy logic).

Line drawings for every detected swing (historical levels stay on the chart and end at the touch bar).

A hidden TouchSignal used to color bars and trigger alerts without distorting the price scale.

The design mirrors Sierra Chart’s “Swing High and Low” with “Extend Swings Until Future Intersection”, but implemented natively in Pine.

How it determines swings

Uses ta.pivothigh() / ta.pivotlow() with length bars left and right.

A swing is confirmed only after there are length bars to the right of the center.

How extensions/lines end

High extensions end when High ≥ level.

Low extensions end when Low ≤ level.

The corresponding line drawing is frozen on the touch bar; the most recent active line continues to extend each new bar.

Inputs

Swing Strength (Bars Left = Right) – symmetric pivot length.

Offset as Percentage – 1 = +1%; positive values push levels outward (High up / Low down), negative pull them inward.

Draw “Extend…Until Future Intersection” Lines – toggle line drawings on/off.

Line Width (Plots + Drawings) – thickness for plots and drawings.

HighExt Color / LowExt Color – colors for the two plots and drawings.

Touch Color – color to paint bars on the touch bar (doesn’t affect scale).

HighExt/LowExt Line Style – choose line style (Solid/Dashed/Dotted) for drawings.

Color Bars on Touch? – enable/disable bar coloring.

Bar Color on High Touch / Low Touch – separate bar colors for each side.

Bar Color Transparency (0..100) – opacity for the bar painting.

Plots

HighExt – latest active high extension only.

LowExt – latest active low extension only.
(Internally there is also a hidden “TouchSignal” plot used for bar coloring & alerts; it’s not displayed to keep the chart scale clean.)

Alerts

Three built-in alertconditions:

Any Extension Touched — triggers when either side is hit.

High Extension Touched — only high level touch.

Low Extension Touched — only low level touch.

Create alerts from the indicator’s “More” (⋯) menu → Add alert → choose one of the conditions.

Styling

Drawings use your selected style (Solid/Dashed/Dotted), color, and width.

Existing historical lines adopt new styles when the script recalculates.

Bar coloring highlights the exact touch candle; disable it if you prefer clean candles.

Notes & tips

Scale-safe: the TouchSignal is hidden (display=none), so it won’t distort the Y-axis.

Performance: TradingView limits scripts to ~500 line objects; this script uses max_lines_count=500. If you hit the cap on long histories, either increase timeframe or disable drawings and rely on the two plots + alerts.

Works on any symbol/timeframe; levels are rounded to the instrument’s minimum tick.

Intended use

For discretionary levels, alerting, and rule-based entries that react to first touch of recent swing extensions. Not financial advice—use at your own risk.
Notas de prensa
Swing High/Low — Extensions (2 Plots + Drawings + Touch Signal)

What it does

This indicator finds **Swing Highs/Lows** using a *symmetric length* (same bars left & right), then creates horizontal **extension levels** that run to the right and **stop at the first price touch** (“extend until future intersection”).

It outputs:

* **Two plots** showing the **most recent active** High/Low extension (great for alerts & strategy logic).
* **Line drawings** for **every** detected swing (historical levels stay on the chart and end at the touch bar).
* A hidden **TouchSignal** used to color bars and trigger alerts **without distorting the price scale**.

The design mirrors Sierra Chart’s “Swing High and Low” + “Extend Swings Until Future Intersection,” implemented natively in Pine.

---

New: Fixed Timeframe (HTF) Mode

Run the swing logic on a **fixed higher timeframe** (e.g., 4h) **while viewing any chart timeframe** (e.g., 30m).

* Enable **Use Fixed Timeframe** and set **Fixed Timeframe** (e.g., `240` for 4h).
* Swings (pivots) and the pivot **center time** are computed on the selected HTF.
* Lines are drawn using **bar time** (`xloc=bar_time`) so they **align perfectly** on lower-timeframe charts.
* **Touch detection** still uses the **chart timeframe’s** High/Low for earliest intrabar touches and cleaner alerts.

> Tip: If you want touch detection on the HTF instead, ask for a toggle and I’ll add it.

---

How it determines swings

* Uses `ta.pivothigh()` / `ta.pivotlow()` with `length` bars left **and** right.
* A swing is confirmed only after there are `length` bars to the right of the center.

How extensions/lines end

* **High extensions** end when **High ≥ level**.
* **Low extensions** end when **Low ≤ level**.
* The corresponding line drawing is frozen on the touch bar; the most recent active line continues to extend each new bar.

---

Inputs

* **Swing Strength (Bars Left = Right)** – symmetric pivot length.
* **Offset as Percentage** – `1` = **+1%**; positive values push levels outward (High up / Low down), negative pull inward.
* **Use Fixed Timeframe?** – toggle HTF mode.
* **Fixed Timeframe (e.g. 240 = 4h)** – timeframe for HTF pivots when enabled.
* **Draw “Extend…Until Future Intersection” Lines** – toggle line drawings on/off.
* **Line Width (Plots + Drawings)** – thickness for plots and drawings.
* **HighExt/LowExt Color** – colors for the two plots and drawings.
* **HighExt/LowExt Line Style** – choose **Solid / Dashed / Dotted** for drawings.
* **Color Bars on Touch?** – enable/disable bar coloring.
* **Bar Color on High Touch / Low Touch** – separate bar colors for each side.
* **Bar Color Transparency (0..100)** – opacity for bar painting.

---

Plots

* **HighExt** — latest active high extension only.
* **LowExt** — latest active low extension only.
*(Internally there’s also a hidden TouchSignal used for bar coloring & alerts; it’s not displayed to keep the chart scale clean.)*

---

Alerts

Three built-in alertconditions:

* **Any Extension Touched** — triggers when *either* side is hit.
* **High Extension Touched** — only high level touch.
* **Low Extension Touched** — only low level touch.

Create alerts from the indicator’s “⋯ More” → **Add alert** → choose one of the conditions.

---

Styling

* Drawings inherit your selected **style** (Solid/Dashed/Dotted), **color**, and **width**.
* Historical lines adopt new styles on recalculation.
* Bar coloring highlights the exact touch candle; disable it if you prefer clean candles.

---

Notes & tips

* **Scale-safe**: the TouchSignal is hidden (`display=none`), so it won’t distort the Y-axis.
* **Performance**: TradingView limits scripts to ~500 line objects; this script requests `max_lines_count=500`. On very long histories, either increase timeframe or disable drawings and use the two plots + alerts.
* Works on any symbol/timeframe; levels are rounded to the instrument’s **minimum tick**.
* HTF mode uses `request.security` safely (no dynamic calls in conditionals); switching the fixed timeframe triggers a clean recomputation.

---

Changelog

* **v1.1** — Added **Fixed Timeframe (HTF) Mode** with perfect alignment on lower TFs; preserved intrabar touch detection on chart TF.
* **v1.0** — Initial release.

---

**Disclaimer**: For educational purposes only. Not financial advice. Use at your own risk.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.