True Strength Index Indicator for ThinkorSwim

APOT7

Member
VIP
Can anyone help is changing this indicator with color? Its called True Strength Index. Its a built in indicator for TOS.

I would like True Strength Index colors to be:
  • Green is its moving upward above zero line
  • red if it moving downward below zero line
  • yellow color if it moving from negative value to positive value under zero line.
  • Purple color if it moving positive value to negative value above zero line.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

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);

plot TSI;
plot Signal;

TSI = if doubleSmoothedAbsDiff == 0 then 0
      else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;
Signal = MovingAverage(averageType, TSI, signalLength);

plot ZeroLine = 0;

TSI.SetDefaultColor(GetColor(1));
Signal.SetDefaultColor(GetColor(8));
Signal.hide();
ZeroLine.SetDefaultColor(GetColor(5));
 
Last edited:

BenTen

Administrative
Staff
VIP
Green is its moving upward above zero line

How do you define "moving upward"?

red if it moving downward below zero line

Define "moving downward"?

yellow color if it moving from negative to positive under zero line.

How do we get a positive value under 0?

Purple color if it moving positive to negative above zero line.

Same as above. How can the value go from positive to negative if it's still above 0?

Here is the best I can do. Green if above 0 and red if below .

Code:
# True Strength Index

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);

plot TSI;
plot Signal;

TSI = if doubleSmoothedAbsDiff == 0 then 0
      else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;
Signal = MovingAverage(averageType, TSI, signalLength);

plot ZeroLine = 0;

TSI.SetDefaultColor(GetColor(1));
Signal.SetDefaultColor(GetColor(8));
Signal.hide();
ZeroLine.SetDefaultColor(GetColor(5));

TSI.AssignValueColor(if TSI > 0 then color.green else color.red);
 

Bladeof300

New member
Can anyone help is changing this indicator with color? Its called True Strength Index. Its a built in indicator for TOS.

I would like True Strength Index colors to be:
  • Green is its moving upward above zero line
  • red if it moving downward below zero line
  • yellow color if it moving from negative to positive under zero line.
  • Purple color if it moving positive to negative above zero line.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

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);

plot TSI;
plot Signal;

TSI = if doubleSmoothedAbsDiff == 0 then 0
      else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;
Signal = MovingAverage(averageType, TSI, signalLength);

plot ZeroLine = 0;

TSI.SetDefaultColor(GetColor(1));
Signal.SetDefaultColor(GetColor(8));
Signal.hide();
ZeroLine.SetDefaultColor(GetColor(5));
Enjoy, if this is not quite what you want let me know and I will try to fix it.


Code:
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);

plot TSI;
plot Signal;

TSI = if doubleSmoothedAbsDiff == 0 then 0
      else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;
Signal = MovingAverage(averageType, TSI, signalLength);

plot ZeroLine = 0;

TSI.SetDefaultColor(GetColor(1));
Signal.SetDefaultColor(GetColor(8));
Signal.Hide();
ZeroLine.SetDefaultColor(GetColor(5));


#TSI.SetPaintingStrategy(PaintingStrategy.LINE);
TSI.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TSI.SetLineWeight(3);
TSI.DefineColor("Positive and Up", Color.GREEN);
TSI.DefineColor("Positive and Down",(CreateColor(153, 0, 242)));
TSI.DefineColor("Negative and Down", Color.RED);
TSI.DefineColor("Negative and Up", Color.YELLOW);
TSI.AssignValueColor(if TSI >= 0 then if TSI > TSI[1] then TSI.Color("Positive and Up") else TSI.Color("Positive and Down") else if TSI < TSI[1] then TSI.Color("Negative and Down") else TSI.Color("Negative and Up"));
 
Last edited:

Bladeof300

New member
@APOT7 Found this one as well it follows a 2 line cross instead of a ZeroLine cross. This is supposed to make the TSI more accurate. I put the same color scheme and line/histogram option in here but it is called Hist instead of TSI.

Code:
##ONE NOTE
#Wednesday, May 15, 2019 - archived 1
def Data = close;
def NA = Double.NaN;
#NA.SetDefaultColor(Color.BLACK);
#NA.HideTitle();
declare lower;
input IndicatorLine = 32;
input Smooth = 5;
input SignalLine = 5;
plot TSIFast = TrueStrengthIndex(LongLength = IndicatorLine, ShortLength = Smooth);
plot TSISlow = ExpAverage(TSIFast, SignalLine);
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
plot Fast = TSIFast;
Fast.SetDefaultColor(Color.BLUE);
plot Slow = TSISlow;
Slow.SetDefaultColor(Color.WHITE);
Slow.SetStyle(Curve.SHORT_DASH);
plot HighLvl = 25;
HighLvl.SetDefaultColor(Color.LIGHT_GREEN);
HighLvl.HideBubble();
HighLvl.HideTitle();
plot LowLvl = -25;
LowLvl.SetDefaultColor(Color.RED);
LowLvl.HideBubble();
LowLvl.HideTitle();

plot Hist = (TSIFast - TSISlow) * 2;
#TSI.SetPaintingStrategy(PaintingStrategy.LINE);
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.DefineColor("Positive and Up", Color.GREEN);
Hist.DefineColor("Positive and Down", (CreateColor(153, 0, 242)));
Hist.DefineColor("Negative and Down", Color.RED);
Hist.DefineColor("Negative and Up", Color.YELLOW);
Hist.AssignValueColor(if Hist >= 0 then if Hist > Hist[1] then Hist.Color("Positive and Up") else Hist.Color("Positive and Down") else if Hist < Hist[1] then Hist.Color("Negative and Down") else Hist.Color("Negative and Up"));

#Arrows
input usearrows = yes;
plot arrowup = if usearrows and Hist crosses above 0 then 0 else Double.NaN;
arrowup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowup.SetDefaultColor(Color.GREEN);
arrowup.SetLineWeight(3);
plot arrowdn = if usearrows and Hist crosses below 0 then 0 else Double.NaN;
arrowdn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowdn.SetDefaultColor(Color.RED);
arrowdn.SetLineWeight(3);
#Clouds
def cond1 = if Hist > 0
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
def cond2 = if Hist < 0
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
input showclouds = yes;
AddCloud(if showclouds
then cond1
else Double.NaN,
cond2,
Color.WHITE, Color.GRAY);
input usealerts = yes;
 

Similar threads

Top