EliCobra

SuperTrend Toolkit

EliCobra Actualizado   
The SuperTrend Toolkit (Super Kit) introduces a versatile approach to trend analysis by extending the application of the SuperTrend indicator to a wide array of @TradingView's built-in or Community Scripts. This tool facilitates the integration of the SuperTrend algorithm with various indicators, including oscillators, moving averages, overlays, and channels.

Methodology:
The SuperTrend, at its core, calculates a trend-following indicator based on the Average-True-Range (ATR) and price action. It creates dynamic support and resistance levels, adjusting to changing market conditions, and aiding in trend identification.
pine_st(simple float factor = 3., simple int length = 10) =>
    float atr = ta.atr(length)
    float up  = hl2 + factor * atr
    up       := up < nz(up[1]) or close[1] > nz(up[1]) ? up : nz(up[1])
    float lo  = hl2 - factor * atr
    lo       := lo > nz(lo[1]) or close[1] < nz(lo[1]) ? lo : nz(lo[1])

    int   dir = na
    float st  = na

    if na(atr[1])
        dir := 1
    else if st[1] == nz(up[1])
        dir := close > up ? -1 : 1
    else
        dir := close < lo ? 1 : -1

    st := dir == -1 ? lo : up

    [st, dir]

@TradingView's native SuperTrend lacks the flexibility to incorporate different price sources into its calculation.
Community scripts, addressed the limitation by implementing the option to input different price sources, for example, one of the most popular publications, @KivancOzbilgic's SuperTrend script.

In May 2023, @TradingView introduced an update allowing the passing of another indicator's plot as a source value via the input.source() function. However, the built-in ta.atr function still relied on the chart's price data, limiting the formerly mentioned scripts to the chart's price data alone.

Unique Approach -
This script addresses the aforementioned limitations by processing the data differently.
Firstly we create a User-Defined-Type (UDT) replicating a bar's open, high, low, close (OHLC) values.
type bar
    float o = open
    float h = high
    float l = low
    float c = close

We then use this type to store the external input data.
src = input.source(close, "External Source")

bar b = bar.new(
       nz(src[1])               ,   open  𝘷𝘢𝘭𝘶𝘦
       math.max(nz(src[1]), src),   high  𝘷𝘢𝘭𝘶𝘦
       math.min(nz(src[1]), src),   low   𝘷𝘢𝘭𝘶𝘦
       src                      )   close 𝘷𝘢𝘭𝘶𝘦

Finally, we pass the data into our custom built SuperTrend with ATR functions to derive the external source's version of the SuperTrend indicator.
supertrend st = b.st(mlt, len)

- Setup Guide -

Utility and Use Cases:
  1. Universal Compatibility - Apply SuperTrend to any built-in indicator or script, expanding its use beyond traditional price data.
    - A simple example on one of my own public scripts -

  2. Trend Analysis - Gain additional trend insights into otherwise mainly mean reverting or volume indicators.

- Alerts Setup Guide -

The Super Kit empowers traders and analysts with a tool that adapts the robust SuperTrend algorithm to a myriad of indicators, allowing comprehensive trend analysis and strategy development.
Notas de prensa:
Added alerts.
Notas de prensa:
Small fix
Notas de prensa:
Added option for any alert call.

Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

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.

¿Quiere utilizar este script en un gráfico?