True Strength Index Indicator for ThinkorSwim

CashMoney

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:
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);
 
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:
@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;
 
Hi Benten,
Your scrip is amazing. Can you create another code for the watchlist column?
Thanks
 
Last edited by a moderator:
@joe362 Sure. try this:

Code:
# True Strength Index
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;
plot value = TSI;
 
@joe362 Sure. try this:

Code:
# True Strength Index
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;
plot value = TSI;
Once again... for the forgetful.. how does one set a Alert, on a watch-list, using only this True Strength Index, for crossover from negative to positive.
I find a very significant different ranging on charting due to 'Average type settings and time frames on the TOS main chart and the number for the watchlist True strength index number... this difference between 'watch-list and main TOS charting has always eluded me where numbers are never the same in my setups. Perhaps a builtin divergence unavoidable?
2 questions, so I might be confusing.
 
@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;
This indicator Is excellent. Can anyone help me with a scan for when the chart shows the arrows? In the condition wizard I set it to show when "arrow down is true" but doesn't seem to be working.
 
@Mrq77 The way the arrow statements are written could be messing up your ability to scan for them because they are set to print on the 0 line and the scanner says that 0 means false so it might not be returning results???

My Work-A-Round: Arrows plot when Hist crosses above 0 (bullish) or crosses below 0 (bear).
Set your scanner to look for Hist crosses above 0. When I ran it on a 15min agg, it got over 1000 equities that fit that condition
5ZuYMQe.png
 
@Mrq77 The way the arrow statements are written could be messing up your ability to scan for them because they are set to print on the 0 line and the scanner says that 0 means false so it might not be returning results???

My Work-A-Round: Arrows plot when Hist crosses above 0 (bullish) or crosses below 0 (bear).
Set your scanner to look for Hist crosses above 0. When I ran it on a 15min agg, it got over 1000 equities that fit that condition
5ZuYMQe.png
Thank you very much this is exactly what I was looking for. I was conditioning the histogram against the zero line in the indicator instead just crossing over a value of 0.0.
 
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"));


There is there away to add in divergence lines ??
 
There is there away to add in divergence lines ??
Here is the one Ive used. It should be mostly the same as what @BenTen and I set up for you a few months ago. The Histogram and the two lines are included. I have also included the Longweak and Shortweak made by @rad14733 using and ergotic calculation, because I personally have found it helpful and reasonably accurate.

If this is not what you want Ill be happy to help you change it but it may be slow work as my life has been extremely busy lately

Code:
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;
#TwoLine Cross Code
input IndicatorLine = 32;
input Smooth = 5;
input SignalLine = 5;
plot TSIFast = TrueStrengthIndex(LongLength = IndicatorLine, ShortLength = Smooth);
TSIFast.SetLineWeight(2);
plot TSISlow = ExpAverage(TSIFast, SignalLine);
TSISlow.SetLineWeight(2);
#Histogram ZeroLine Cross Code
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(0, 140, 95)));
TSI.DefineColor("Negative and Down", Color.RED);
TSI.DefineColor("Negative and Up", (CreateColor(128, 57, 0)));
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"));


def ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal;
def avgErgodic = MovingAverage(AverageType.SIMPLE, ErgodicOsc, 8);

plot longweak = if ErgodicOsc > 0 and ErgodicOsc < avgErgodic and ErgodicOsc < ErgodicOsc[1] and ErgodicOsc[1] > avgErgodic[1] then 0 else Double.NaN;
longweak.SetPaintingStrategy(PaintingStrategy.POINTS);
longweak.SetDefaultColor(Color.MAGENTA);
longweak.SetLineWeight(5);
longweak.HideTitle();

plot shortweak = if ErgodicOsc < 0 and ErgodicOsc > avgErgodic and ErgodicOsc > ErgodicOsc[1] and ErgodicOsc[1] < avgErgodic[1] then 0 else Double.NaN;
shortweak.SetPaintingStrategy(PaintingStrategy.POINTS);
shortweak.SetDefaultColor(Color.CYAN);
shortweak.SetLineWeight(5);
shortweak.HideTitle();
 
Hi! I have a paint bar in TradeStation that paints bars green / red based on change in momentum in TSI (True Strength Index). It probably is pretty easy for someone to convert to TOS / thinkscript if someone feels like giving it a shot. Thanks in advance! I will include the TSI thinkscript code for reference below (keep in mind, I don't need to plot TSI) as well as the TradeStation paint bar easylanguage:

A. TOS Thinkscript (TSI):

declare lower;

input longLength = 25;
input shortLength = 13;
input signalLength = 7;
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;
plot MA = Average(TSI,5);
plot UpperLevel = 20;
plot LowerLevel = -20;

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


B. TradeStation Paint Bar Easylanguage:

Inputs: Price(c), r(7), s(20), u(1), Zeroline(0), SmthLen(7),
upcolor(green), downcolor(red), linesize(1);

Value1= XAverage(TSI(Price, r, s, u), SmthLen);

plotPaintBar(h,l) ;

if Value1 > Value1[1] then
setplotcolor[0](1,upcolor)
else

if Value1 < Value1[1] then
setplotcolor[0](1,downcolor);
 
Hi! I have a paint bar in TradeStation that paints bars green / red based on change in momentum in TSI (True Strength Index). It probably is pretty easy for someone to convert to TOS / thinkscript if someone feels like giving it a shot. Thanks in advance! I will include the TSI thinkscript code for reference below (keep in mind, I don't need to plot TSI) as well as the TradeStation paint bar easylanguage:
TSI Dashboard For ThinkOrSwim
Here is my TSI Dashboard.
You should be able to amend it to meet your needs.

This version is superior to the Tradestation code you listed. Your code only looks at above and below zero. This takes all the conditions into account.

I use the True Strength dashboard to weed out the false signals of other studies.
7xPzgeb.png

Ruby:
###########################################################################
#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);
 
Last edited:
Thanks again -- I see the lower part but the bars don't paint. Any thoughts? Appreciate your help!
 
Last edited by a moderator:
Thanks again -- I see the lower part but the bars don't paint. Any thoughts? Appreciate your help!
I thought you asked for the horizontal line. The study creates a paint bar. as shown in the lower study above.
Are you asking for the upper chart candles to paint? Because that wasn't part of the TradeStation code that you shared.

To paint the candles in the upper chart add the following to the script:
Ruby:
AssignPriceColor(
    if bullish then Color.green else
        if bearish then Color.red else Color.GRAY);
 
Last edited:
@TraderC

If you don't want the lower study at all, remove these lines:
declare lower;
and
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);
 
I have the following code updated with divergence line. Can anyone help with adding paint bar color according to HISTOGRAM COLORS.

Thank you.

Here is the code.
Code:
# True Strength Index Bladeof300

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

input n = 20;
def bar = BarNumber();
def Currh = if tsi > zeroline
then fold i = 1 to Floor(n / 2)
with p = 1
while p
do tsi > getValue(tsi, -i)
else 0;
def CurrPivotH = if (bar > n and
tsi == highest(tsi, Floor(n/2)) and
Currh)
then tsi
else double.NaN;
def Currl = if tsi < zeroline
then fold j = 1 to Floor(n / 2)
with q = 1
while q
do tsi < getValue(tsi, -j)
else 0;
def CurrPivotL = if (bar > n and
tsi == lowest(tsi, Floor(n/2)) and
Currl)
then tsi
else double.NaN;
def CurrPHBar = if !isNaN(CurrPivotH)
then bar
else CurrPHBar[1];
def CurrPLBar = if !isNaN(CurrPivotL)
then bar
else CurrPLBar[1];
def PHpoint = if !isNaN(CurrPivotH)
then CurrPivotH
else PHpoint[1];
def priorPHBar = if PHpoint != PHpoint[1]
then CurrPHBar[1]
else priorPHBar[1];
def PLpoint = if !isNaN(CurrPivotL)
then CurrPivotL
else PLpoint[1];
def priorPLBar = if PLpoint != PLpoint[1]
then CurrPLBar[1]
else priorPLBar[1];
def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);
def pivotHigh = if HighPivots
then CurrPivotH
else double.NaN;
plot PlotHline = pivotHigh;
PlotHline.enableApproximation();
PlotHline.SetDefaultColor(GetColor(5));
PlotHline.SetStyle(Curve.LONG_DASH);
PlotHline.SetLineWeight(5);
plot pivotLow = if LowPivots
then CurrPivotL
else double.NaN;
pivotLow.enableApproximation();
pivotLow.SetDefaultColor(GetColor(6));
pivotLow.SetStyle(Curve.LONG_DASH);
pivotLow.SetLineWeight(3);
plot PivotDot = if !isNaN(pivotHigh)
then pivotHigh
else if !isNaN(pivotLow)
then pivotLow
else double.NaN;
pivotDot.SetDefaultColor(GetColor(3));
pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
pivotDot.SetLineWeight(3);
 
Last edited by a moderator:
TSI Dashboard For ThinkOrSwim
Here is my TSI Dashboard.
You should be able to amend it to meet your needs.

This version is superior to the Tradestation code you listed. Your code only looks at above and below zero. This takes all the conditions into account.

I use the True Strength dashboard to weed out the false signals of other studies.
7xPzgeb.png

Ruby:
###########################################################################
#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);
@MerryDay Thank you very much! This is great. Can we make it as scanners: one for bullish, another for bearish?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
465 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top