Super Trend Fusion

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #259684 quote
    brian gilbert
    Participant
    Junior

    Hi, I found an interesting indicator that combines trend direction, momentum, and a volatility filter. I’d like to test it on our platform. Can you help? Below is the link to the page and the related code. Thanks in advance!


    https://www.tradingview.com/script/Qe9aWBlF-SuperTrend-Fusion-Trend-Momentum-Volatility-Filter/


    Pine script code:

    // This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

    // © AlgoTrade_Pro

    // This script includes an adapted Average Force function originally published as open-source on TradingView by its author – racer8


    //@version=6

    indicator(“SuperTrend Fusion — ATP”, overlay = true, timeframe = “”, timeframe_gaps = true)



    //──────────────────────────

    // INPUTS

    //──────────────────────────


    // 1) SuperTrend – Trend component

    var g_trend = “SuperTrend – Trend”

    atrPeriod = input.int(10, “ATR Length”, minval = 1, group = g_trend)

    factor   = input.float(3, “Factor”,   minval = 0.01, step = 0.01, group = g_trend)


    // 2) Average Force – Momentum filter

    var g_mom = “Average Force – Momentum”

    useAfFilter = input.bool(true, “Use AF Filter”, group = g_mom)

    afPeriod  = input.int(18,  “AF Period”,   minval = 1, group = g_mom)

    afSmooth  = input.int(6,   “AF Smooth”,   minval = 1, group = g_mom)


    // 3) Choppiness Index – Volatility / trend filter

    var g_chop = “Choppiness Index – Volatility”

    useChopFilter = input.bool(true, “Use Chop Filter”, group = g_chop)

    chopLength  = input.int(14,   “Chop Length”,   minval = 1, group = g_chop)

    chopThreshold = input.int(50,   “Chop Threshold”, minval = 1, maxval = 100, group = g_chop)



    //──────────────────────────

    // CORE CALCULATIONS

    //──────────────────────────


    // 1) SuperTrend base

    [stValue, stDirection] = ta.supertrend(factor, atrPeriod)

    isUpTrend  = stDirection < 0

    isDownTrend = stDirection > 0


    // 2) Average Force function

    af(src, hi, lo, length, postSmooth) =>

      p     = math.max(1, int(length))

      highestHi = ta.highest(hi, p)

      lowestLo = ta.lowest(lo, p)

      ranges  = highestHi – lowestLo

      raw    = ranges == 0.0 ? 0.0 : (src – lowestLo) / ranges – 0.5

      ta.sma(raw, math.max(1, int(postSmooth)))


    afValue = af(close, high, low, afPeriod, afSmooth)


    // 3) Choppiness Index

    highestHiChop = ta.highest(high, chopLength)

    lowestLoChop = ta.lowest(low, chopLength)

    rangeChop   = highestHiChop – lowestLoChop

    choppiness  = rangeChop != 0 ? 100 * math.log10(math.sum(ta.atr(1), chopLength) / rangeChop) / math.log10(chopLength) : 100



    //──────────────────────────

    // FUSION LOGIC

    //──────────────────────────


    bullMomentum  = afValue > 0

    bearMomentum  = afValue < 0

    marketTrending = choppiness < chopThreshold


    bullFilterOk = (not useAfFilter or bullMomentum) and (not useChopFilter or marketTrending)

    bearFilterOk = (not useAfFilter or bearMomentum) and (not useChopFilter or marketTrending)


    rawLongFlip = ta.change(stDirection) < 0

    rawShortFlip = ta.change(stDirection) > 0


    longCondition = rawLongFlip and bullFilterOk

    shortCondition = rawShortFlip and bearFilterOk


    rawLongFlipFiltered = rawLongFlip and not longCondition

    rawShortFlipFiltered = rawShortFlip and not shortCondition



    //──────────────────────────

    // VISUAL OUTPUT — SINGLE LINES

    //──────────────────────────


    // Premium signal colors

    longColor = color.new(color.aqua,  0)

    shortColor = color.new(color.orange, 0)


    // Fusion SuperTrend (bold)

    plot(longCondition or shortCondition ? stValue : na, “Fusion Trend”,

       color = longCondition ? longColor : shortCondition ? shortColor : na,

       linewidth = 3, style = plot.style_linebr)


    // Base SuperTrend with colors

    plot(stValue, “Base SuperTrend”,

       color = isUpTrend ? color.new(color.aqua, 0) : color.new(color.orange, 0),

       style = plot.style_linebr, linewidth = 2)


    // Bar colors

    barcolor(longCondition ? color.new(longColor, 70) : shortCondition ? color.new(shortColor, 70) : na)


    // Choppy background

    bgcolor(useChopFilter and not marketTrending ? color.new(color.orange, 92) : na, force_overlay = true)


    // Entry markers (WHITE text color, more pro wording)

    plotshape(longCondition, “Fusion Long Entry”,

         style = shape.triangleup,  location = location.belowbar,

         size = size.small, color = longColor)


    plotshape(shortCondition, “Fusion Short Entry”,

         style = shape.triangledown, location = location.abovebar,

         size = size.small, color = shortColor)


    // Filtered signals (X marks)

    plotshape(rawLongFlipFiltered, “Filtered Long Flip”,

         style = shape.xcross, location = location.belowbar,

         size = size.tiny, color = color.new(color.orange, 0))


    plotshape(rawShortFlipFiltered, “Filtered Short Flip”,

         style = shape.xcross, location = location.abovebar,

         size = size.tiny, color = color.new(color.orange, 0))



    //──────────────────────────

    // ALERTS

    //──────────────────────────

    alertcondition(longCondition, title = “Fusion Long”, message = “SuperTrend Fusion — Long signal”)

    alertcondition(shortCondition, title = “Fusion Short”, message = “SuperTrend Fusion — Short signal”)




             








       

               

                        



        

           

                       

                        



       

           

                       = g_chop )  

    chopThreshold = input.int ( 50 , “Soglia di taglio” , minval = 1 , maxval = 100 , group = g_chop )                  //────────────────────────── // CALCOLI PRINCIPALI //────────────────────────── // 1) SuperTrend base [ stValue , stDirection ] = ta.supertrend ( factor , atrPeriod ) isUpTrend = stDirection < 0 isDownTrend = stDirection > 0 // 2) Funzione di forza media af ( src , hi , lo , length , postSmooth ) => p = math.max ( 1 , int ( length )) highestHi = ta.highest ( hi , p ) lowestLo = ta.lowest ( lo , p ) ranges = highestHi – lowestLo raw = ranges == 0.0 ? 0.0 : ( src – lowestLo ) / ranges – 0.5 ta.sma ( raw , math.max ( 1 , int ( postSmooth ))) afValue = af ( close , high , low , afPeriod , afSmooth ) // 3) Indice di irregolarità highestHiChop = ta.highest ( high , chopLength ) lowestLoChop = ta.lowest ( low , chopLength ) rangeChop = highestHiChop – lowestLoChop choppiness = rangeChop != 0 ? 100 * math.log10 ( math.sum ( ta.atr








        

          

        



         

                   

           

            

               

                            

          


          



       

        

            

               ( 1 ) , chopLength ) / rangeChop ) / math.log10 ( chopLength ) : 100        //────────────────────────── // LOGICA DI FUSIONE //────────────────────────── bullMomentum = afValue > 0 bearMomentum = afValue < 0 marketTrending = choppiness < chopThreshold bullFilterOk = ( non useAfFilter o bullMomentum ) e ( non useChopFilter o marketTrending ) bearFilterOk = ( non useAfFilter o bearMomentum ) e ( non useChopFilter o marketTrending ) rawLongFlip = ta.change ( stDirection ) < 0 rawShortFlip = ta.change ( stDirection ) > 0 longCondition = rawLongFlip e bullFilterOk shortCondition = rawShortFlip e bearFilterOk rawLongFlipFiltered = rawLongFlip e non longCondition rawShortFlipFiltered = rawShortFlip e non shortCondition //─────────────────────────── // OUTPUT VISIVO — LINEE SINGOLE //────────────────────────── // Colori del segnale premium longColor = color.new ( color.aqua , 0 ) shortColor = color.new ( color.orange , 0 ) // Fusion SuperTrend (grassetto) plot ( longCondition or shortCondition ? stValue : na , “Tendenza Fusione” , colore = longCondition ? longColor : shortCondition ? shortColor : na , larghezza linea = 3 , stile = plot.style_linebr







          

          

        


              

              


         

        


          

        


           

         








          

        



           

                   

              ) // SuperTrend di base con grafico a colori ( stValue , “SuperTrend di base” , color = isUpTrend ? color.new ( color.aqua , 0 ) : color.new ( color.orange , 0 ) , style = plot.style_linebr , linewidth = 2 ) // Colori delle barre barcolor ( longCondition ? color.new ( longColor , 70 ) : shortCondition ? color.new ( shortColor , 70 ) : na ) // Sfondo spezzato bgcolor ( useChopFilter e non marketTrending ? color.new ( color.orange , 92 ) : na , force_overlay = true ) // Indicatori di ingresso (colore del testo BIANCO, linguaggio più professionale ) plotshape ( longCondition , “Ingresso lungo Fusion” , style = shape.triangleup , location = location.belowbar , size = size.small , color = longColor ) plotshape ( shortCondition , “Fusion Short Entry” , style = shape.triangledown , location = location.abovebar , size = size.small , color = shortColor ) // Segnali filtrati (segni X) plotshape ( rawLongFlipFiltered , “Filtered Long Flip” , style = shape.xcross , location = location.belowbar , size = size.tiny , color = color.new ( color.orange , 0 )) plotshape ( rawShortFlipFiltered , “Filtered Short Flip” , style =



     

                 

              



              



               



      

                     

                   


     

                   

                   



      

                   

                    


     

                shape.xcross , location = location.abovebar ,    size = size.tiny , color = color.new ( color.orange , 0 )) //────────────────────────── // AVVISI //────────────────────────── alertcondition ( longCondition , title = “Fusion Long” , message = “SuperTrend Fusion — Segnale Long” ) alertcondition ( shortCondition , title = “Fusion Short” , messaggio = “SuperTrend Fusion — Segnale di vendita allo scoperto “

                    






            

          

    #259688 quote
    Iván González
    Moderator
    Master

    Hi, here you have:

    //-------------------------------------------------//
    // PRC_SuperTrend Fusion
    // Adapted from PineScript [AlgoTrade_Pro]
    // Average Force function originally by racer8
    // version = 0
    // 31.03.2026
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //-------------------------------------------------//
    
    // === INPUTS ===
    // SuperTrend
    atrPeriod = 10      // ATR Length
    stFactor = 3        // SuperTrend Factor
    
    // Average Force – Momentum filter
    useAFfilter = 1     // 1=use AF filter, 0=disable
    afPeriod = 18       // AF Period
    afSmooth = 6        // AF Smoothing
    
    // Choppiness Index – Volatility filter
    useChopFilter = 1   // 1=use Chop filter, 0=disable
    chopLength = 14     // Chop Length
    chopThreshold = 50  // Chop Threshold (below = trending)
    
    // === CORE CALCULATIONS ===
    
    // 1) SuperTrend
    stVal = Supertrend[stFactor, atrPeriod]
    isUpTrend = (close > stVal)
    isDownTrend = (close < stVal)
    
    // Detect flips
    rawLongFlip = (isUpTrend AND NOT isUpTrend[1])
    rawShortFlip = (isDownTrend AND NOT isDownTrend[1])
    
    // 2) Average Force (normalized stochastic centered at 0, then smoothed)
    hiN = highest[afPeriod](high)
    loN = lowest[afPeriod](low)
    rng = hiN - loN
    IF rng <> 0 THEN
       rawAF = (close - loN) / rng - 0.5
    ELSE
       rawAF = 0
    ENDIF
    afValue = average[afSmooth](rawAF)
    
    // 3) Choppiness Index
    hiChop = highest[chopLength](high)
    loChop = lowest[chopLength](low)
    rangeChop = hiChop - loChop
    myTR = max(high - low, max(abs(high - close[1]), abs(low - close[1])))
    sumTR = summation[chopLength](myTR)
    IF rangeChop <> 0 THEN
       choppiness = 100 * log(sumTR / rangeChop) / log(chopLength)
    ELSE
       choppiness = 100
    ENDIF
    
    // === FUSION LOGIC ===
    bullMomentum = (afValue > 0)
    bearMomentum = (afValue < 0)
    marketTrending = (choppiness < chopThreshold)
    
    // Build filter conditions
    bullFilterOk = 1
    IF useAFfilter AND NOT bullMomentum THEN
       bullFilterOk = 0
    ENDIF
    IF useChopFilter AND NOT marketTrending THEN
       bullFilterOk = 0
    ENDIF
    
    bearFilterOk = 1
    IF useAFfilter AND NOT bearMomentum THEN
       bearFilterOk = 0
    ENDIF
    IF useChopFilter AND NOT marketTrending THEN
       bearFilterOk = 0
    ENDIF
    
    // Fusion signals (flip + filters confirmed)
    longCondition = (rawLongFlip AND bullFilterOk)
    shortCondition = (rawShortFlip AND bearFilterOk)
    
    // Filtered flips (flip but filters NOT confirmed)
    rawLongFiltered = (rawLongFlip AND NOT longCondition)
    rawShortFiltered = (rawShortFlip AND NOT shortCondition)
    
    // === VISUAL OUTPUT ===
    
    // SuperTrend line color
    IF isUpTrend THEN
       rLine = 0
       gLine = 255
       bLine = 255
    ELSE
       rLine = 255
       gLine = 165
       bLine = 0
    ENDIF
    
    // ATR for label offset
    atr14 = averagetruerange[14]
    
    // Fusion entry signals (arrows)
    IF longCondition THEN
       drawarrowup(barindex, low - atr14 * 0.5) coloured(0, 255, 255)
    ENDIF
    IF shortCondition THEN
       drawarrowdown(barindex, high + atr14 * 0.5) coloured(255, 165, 0)
    ENDIF
    
    // Filtered flips (X marks — signal rejected by filters)
    IF rawLongFiltered THEN
       drawtext("✖", barindex, low - atr14 * 0.3) coloured(255, 165, 0)
    ENDIF
    IF rawShortFiltered THEN
       drawtext("✖", barindex, high + atr14 * 0.3) coloured(255, 165, 0)
    ENDIF
    
    // Choppy background
    IF useChopFilter AND NOT marketTrending THEN
       backgroundcolor(255, 165, 0, 20)
    ENDIF
    
    RETURN stVal coloured(rLine, gLine, bLine) style(line, 2) AS "SuperTrend"
    


    brian gilbert thanked this post
    TSLA-Diario-4.png TSLA-Diario-4.png
    #259697 quote
    brian gilbert
    Participant
    Junior

    Wow, thank you very much, Ivan, “gracias”!!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by brian gilbert
1 day, 9 hours ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 03/31/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...