OPEN-SOURCE SCRIPT
Actualizado trend line [odnac]

Overview
Trendline Conditions
Pivot Detection Methods (4 modes)
Settings
> Trendline Mode : Select pivot detection method
> Swing Left/Right Bars : Number of bars on each side for Swing Confirm mode
> Pivot Left/Right Bars : Number of bars on each side for Pivot High/Low mode
> Fractal Bars : Number of bars on each side for Williams Fractal
> Donchian Length : Lookback period for Donchian mode
> Show Labels : Toggle swing point labels on/off
> Show High/Low Trendlines : Toggle high/low trendlines on/off
> High/Low Line Color : Color of trendlines
Notes
This indicator automatically detects swing highs and swing lows, and draws trendlines connecting valid highs to highs and lows to lows. Lines automatically terminate when price breaks through them. Four pivot detection methods are supported.
Trendline Conditions
- High Trendline (Descending Resistance): Drawn only when the current swing high is lower than the previous swing high
- Low Trendline (Ascending Support): Drawn only when the current swing low is higher than the previous swing low
- Wick Breach Filter: If any candle wick (high/low) between two pivot points touches or crosses the trendline, the line is not drawn
- Breakout Detection: When the closing price crosses the trendline, the line is terminated at that bar
Pivot Detection Methods (4 modes)
- Swing Confirm
Detects highs and lows based on left/right bar count, but only accepts pivot points that pass an additional bearish/bullish confirmation condition. Produces fewer but more reliable swing points with less noise. - Pivot High/Low
Uses raw ta.pivothigh / ta.pivotlow values directly. Any point that is higher or lower than the surrounding N bars on each side is recognized as a pivot. - Williams Fractal
Confirms a pivot when the center bar's high/low is greater or less than N bars on both sides. The default value of 2 produces the classic 5-bar fractal pattern. - Donchian
Uses the highest high and lowest low over N bars as pivot points. A simple and clean channel-based pivot detection method.
Settings
> Trendline Mode : Select pivot detection method
> Swing Left/Right Bars : Number of bars on each side for Swing Confirm mode
> Pivot Left/Right Bars : Number of bars on each side for Pivot High/Low mode
> Fractal Bars : Number of bars on each side for Williams Fractal
> Donchian Length : Lookback period for Donchian mode
> Show Labels : Toggle swing point labels on/off
> Show High/Low Trendlines : Toggle high/low trendlines on/off
> High/Low Line Color : Color of trendlines
Notes
- Trendlines are drawn based on confirmed pivot points only, with no repainting
- The wick breach filter may result in fewer lines being drawn. This is intentional — only clean, high-confidence trendlines are displayed
- Each mode has its own independent parameters, so be sure to adjust settings individually when switching modes
Notas de prensa
Swing Confirm mode updated- Replaced rightBars window with unlimited confirmation — no time limit on swing candidates
- A swing high is confirmed when N consecutive renewing bearish closes (each lower than the last) are detected after the candidate
- A swing high is confirmed when N consecutive renewing bullish closes (each higher than the last) are detected after the candidate
- Swing point is plotted at the actual pivot bar, not the confirmation bar
- Right Bars setting replaced with Confirmation Count (default 3)
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.