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 “