###########################################################################
#TSItsiTSI
#Settings
#standard = 25,13,8
#quicker = 13,7,8
#daily, weekly & monthly = 40,20,8
#A quick review of the BUY signals:
#1. TSI crosses above zero.
#2. TSI crosses above moving average.
#3. TSI makes higher low (below zero) while price makes a lower low
#And the SELL signals:
#1. TSI crosses below zero
#2. TSI crosses below moving average
#3. TSI makes a lower high (above zero) while price makes a higher high
#4. Trend of TSI breaks down
declare lower;
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;
def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diff), longLength), shortLength);
def TSI = if doubleSmoothedAbsDiff == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;
def Signal = MovingAverage(averageType, TSI, signalLength);
##########################################################################
#TSI Short Term
input longLengths = 8;
input shortLengths = 8;
input signalLengths = 3;
def diffs = close - close[1];
def doubleSmoothedAbsDiffs = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffs), longLengths), shortLengths);
def TSIs;
TSIs = if doubleSmoothedAbsDiffs == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffs, longLengths), shortLengths)) / doubleSmoothedAbsDiffs;
##########################################################################
#TSI Long Term
input longLengthl = 40;
input shortLengthl = 20;
input signalLengthl = 8;
def diffl = close - close[1];
def doubleSmoothedAbsDiffl = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffl), longLengthl), shortLengthl);
def TSIl;
TSIl = if doubleSmoothedAbsDiffl == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffl, longLengthl), shortLengthl)) / doubleSmoothedAbsDiffl;
######################################################################
#TSI Horizontal Line
def bullish = TSIl > TSIl[1] and TSIs > TSIs[1] and TSI > TSI[1];
def bearish = TSIl < TSIl[1] and TSIs < TSIs[1] and TSI < TSI[1];
def bar = barNumber();
plot TSI_Dashboard = 0.00;
TSI_Dashboard.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TSI_Dashboard.SetLineWeight(2);
TSI_Dashboard.AssignValueColor(if bullish then Color.cyan else if bearish then Color.dark_orange else Color.GRAY);