this is a code i copied form tradingview. is it possible to translate it to a thinkorswim code?
Code:
//@version=3
study(title="Trend Intensity Index [DW]", shorttitle="TII [DW]", overlay=false)
//by Donovan Wall
//This study is a simple variation of M. H. Pee's Trend Intensity Index that includes two signal lines rather than one for additional trend confirmation.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source
src = input(defval=close, title="Source")
per = input(defval=34, title="TII Period")
eper = input(defval=5, title="Signal 1 Period")
eper2 = input(defval=21, title="Signal 2 Period")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Average Price
av = sma(src, per)
//Half Period
per2 = (per % 2 == 0) ? per/2 : (per + 1)/2
//Deviations
dev = src - av
udev = dev > 0 ? abs(dev) : 0
ddev = dev < 0 ? abs(dev) : 0
sudev = sum(udev, per2)
sddev = sum(ddev, per2)
//Trend Intensity Index
tii = (100*sudev)/(sudev + sddev)
sig = ema(tii, eper)
sig2 = ema(tii, eper2)
//Bounds
hb = 100
ub = 80
cent = 50
db = 20
lb = 0
//Color
ticolor = tii > 80 ? lime : tii < 20 ? red : black
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Axis
hbplot = plot(hb, color=lime, title="Ceiling")
ubplot = plot(ub, color=lime, title="Strong Uptrend Threshold")
centplot = plot(cent, color=orange, title="Midline")
dbplot = plot(db, color=red, title="Strond Downtrend Threshold")
lbplot = plot(lb, color=red, title="Floor")
//Axis Fills
fill(hbplot, ubplot, color=green, transp=80, title="Strong Uptrend Zone")
fill(dbplot, lbplot, color=maroon, transp=80, title="Strong Downtrend Zone")
//TII Plots
tiiplot = plot(tii, color=black, style=linebr, linewidth=2, title="Trend Intensity Index")
sigplot = plot(sig, color=yellow, style=linebr, linewidth=2, title="Signal Line 1")
sig2plot = plot(sig2, color=orange, style=linebr, linewidth=2, title="Signal Line 2")
//TII Fill
fill(tiiplot, centplot, color=ticolor, transp=80)
Last edited by a moderator: