// TSI indicator
usetf = ParamToggle("Use TF", "No|Yes", 0) ;
tf = Param("TF", 6, 1, 10000) ;
p1 = 25 ;
p2 = 13 ;
sigp = 3 ;
showsig = ParamToggle("Show Signal", "No|Yes", 1) ;
Onsignal = ParamToggle("Rib on", "Slope|Signal", 1) ;
expandmode = expandFirst ;
tfs = tf * in1Minute;
if (usetf)
TimeFrameSet(tfs) ;
pc = C - Ref(C, -1) ;
pc1 = EMA(pc, p1) ;
pc2 = EMA(pc1, p2) ;
apc = abs(C - Ref(C, -1)) ;
apc1 = EMA(apc, p1) ;
apc2 = EMA(apc1, p2) ;
tsie = tsi = 100 * (pc2 / apc2) ;
sige = sig = EMA(tsi, sigp) ;
Clrlong = colorBlue ;
Clrlongpb = colorLightBlue ;
Clrshort = colorRed ;
Clrshortpb = colorRose ;
Clrrib = H-H ;
if (Onsignal)
Clrrib = IIf(tsi > 0, IIf(tsi >= sig, Clrlong, Clrlongpb),
IIf(tsi <= sig, Clrshort, Clrshortpb)) ;
else
Clrrib = IIf(tsi > 0, IIf(tsi > Ref(tsi, -1), Clrlong, Clrlongpb),
IIf(tsi < Ref(tsi, -1), Clrshort, Clrshortpb)) ;
Clrribe = Clrrib ;
if (usetf)
{
tsie = TimeFrameExpand(tsi, tfs, expandmode) ;
sige = TimeFrameExpand(sig, tfs, expandmode) ;
Clrribe = TimeFrameExpand(Clrrib, tfs, expandmode) ;
TimeFrameRestore() ;
}
Plot(tsie, "TSI", colorBlue) ;
if (showsig)
Plot(sige, "Signal", colorRed) ;
showrib = True ;
ribht = 3 ;
if (showrib)
Plot(ribht, "", Clrribe, styleArea|styleOwnScale|styleNoLabel, 0, 100) ;