Trend Directional Force Index (TDFI) - Tradingview

C

ccrkk

New member
VIP
Hello,

I found this trend trading indicator on Tradingview and was wondering if someone could possibly convert it into a TOS study. I scrolled though charts on Tradingview with the indicator and it really did a nice job of keeping you out of trades while in a sideways market with the ".05" high/low filter. Would like to test it out on TOS to analyze it further and conduct more backtest on it. Any help would be greatly appreciated.

Below is the code from Tradingview: (All credit goes to "causecelebre" from Tradingview for this indicator)

Code:
//@version=4
study("Trend Direction Force Index v2 - TDFI [wm]", shorttitle = "TDFI v2 [wm]", overlay = false)

lookback = input(13, title = "Lookback")
mmaLength = input(13, title = "MMA Length")
mmaMode = input(title = "MMA Mode", defval="ema", options=["ema", "wma", "swma", "vwma", "hull", "tema"])
smmaLength = input(13)
smmaMode = input(title = "SMMA Mode", defval="ema", options=["ema", "wma", "swma", "vwma", "hull", "tema"])
nLength = input(3, title = "N Length")
filterHigh = input(0.05, title = "Filter High")
filterLow = input(-0.05, title = "Filter Low")
price = input(close, "Period")

tema(src, len) =>
    ema1 = ema(src, len)
    ema2 = ema(ema1, len)
    ema3 = ema(ema2, len)
    (3 * ema1) - (3 * ema2) + ema3
   
ma(mode, src, len) =>
     mode == "ema" ? ema(src, len) :
     mode == "wma" ? wma(src, len) :
     mode == "swma" ? swma(src) :
     mode == "vwma" ? vwma(src, len) :
     mode == "hull" ? wma((2 * wma(src, len / 2)) - wma(src, len), round(sqrt(len))) :
     mode == "tema" ? tema(src, len) :
     sma(src, len)
    
tdfi() =>
    mma = ma(mmaMode, price * 1000, mmaLength)
    smma = ma(smmaMode, mma, smmaLength)
    impetmma = mma - mma[1]
    impetsmma = smma - smma[1]
    divma = abs(mma - smma)
    averimpet = (impetmma + impetsmma) / 2
    tdf = pow(divma, 1) * pow(averimpet, nLength)
    tdf / highest(abs(tdf), lookback * nLength)
   
signal = tdfi()
c = signal > filterHigh ? color.green : signal < filterLow ? color.red : color.gray

plot(signal, linewidth = 2, color = c)
hline(filterHigh, color = color.black)
hline(filterLow, color = color.black)
 
Top