RSI - TSI Indicator For ThinkOrSwim

Nich76

New member
Can someone help me combine RSI and TrueStrengthIndex into one indicator? I tried to copy/paste into Think Script, but it does not work. I am seeing where RSI crosses above TrueStrengthIndex for an intraday play indicates a call. The opposite is true when RSI crosses below TrueStrengthIndex, this indicated a put. I can put them on the same line in the desktop application, but the mobile version does not allow two indicators to overlap. That is my inspiration to combine them into one indicator that IOS recognizes.
 

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

@Nich76 Try this:

a.png


Code:
declare lower;

script normalized {
    input data   = close;
    input Min    = 0;
    input Max    = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

### Relative Strength Index (RSI) ###

input length = 14;
input price = close;
def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot x = normalized(RSI);
x.SetDefaultColor(Color.GREEN);
x.SetLineWeight(3);



### True Strength Index (TSI) ###

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

plot y = normalized(TSI);
y.SetDefaultColor(Color.RED);
y.SetLineWeight(3);

Good Luck and Good Trading :cool:
 
Last edited:
@Nich76 Try this:

a.png


Code:
declare lower;

script normalized {
    input data   = close;
    input Min    = 0;
    input Max    = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

### Relative Strength Index (RSI) ###

input length = 14;
input price = close;
def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot x = normalized(RSI);
x.SetDefaultColor(Color.GREEN);
x.SetLineWeight(3);



### True Strength Index (TSI) ###

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

plot y = normalized(TSI);
y.SetDefaultColor(Color.RED);
y.SetLineWeight(3);

Good Luck and Good Trading :cool:
This looks good. I will watch it this coming week to see if my suspicions are true. I had to delete the first line "declare lower;" and I had to delete line 37 "input averageType = AverageType.EXPONENTIAL;" for it to show up. Prior to deleting those lines it would not display on my desktop or IOS (mobile).

I am thinking this will be good for intraday options for entry and exits. I really appreciate your help!
 
...I had to delete the first line "declare lower;" and I had to delete line 37 "input averageType = AverageType.EXPONENTIAL;" for it to show up. Prior to deleting those lines it would not display on my desktop or IOS (mobile)...

@Nich76: I don't have TOS Mobile, so, unfortunately I can't test the code for potential bugs/display issues. I use TOS Desktop, so I went back and debugged the code again. It turns out there was an issue with the AverageType statement at Line 37. I have corrected the issue, so it should work on TOS Desktop. As for TOS Mobile, correcting the AverageType issue and commenting out the Declare Lower statement should display the indicator on your phone, at least that is what I'm hoping :)

If you delete the hashtag I put in front of the Declare Lower statement, you should be able to view the indicator in TOS Desktop as a lower study. If you have a screen-capture program, could you capture what you're looking at...it would be a big help on this end to be able to see the issues you're having. That said, hopefully everything will be working properly negating the need for any further speculative efforts...

Code:
#declare lower;

script normalized {
    input data   = close;
    input Min    = 0;
    input Max    = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

### Relative Strength Index (RSI) ###

input length = 14;
input price = close;
def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot x = normalized(RSI);
x.SetDefaultColor(Color.GREEN);
x.SetLineWeight(3);



### True Strength Index (TSI) ###

input longLength = 25;
input shortLength = 13;
#input signalLength = 8;
input averageType2 = AverageType.EXPONENTIAL;

def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diff), longLength), shortLength);

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

plot y = normalized(TSI);
y.SetDefaultColor(Color.RED);
y.SetLineWeight(3);

Hope this helps!

Good Luck and Good Trading :cool:
 
@Nich76: I don't have TOS Mobile, so, unfortunately I can't test the code for potential bugs/display issues. I use TOS Desktop, so I went back and debugged the code again. It turns out there was an issue with the AverageType statement at Line 37. I have corrected the issue, so it should work on TOS Desktop. As for TOS Mobile, correcting the AverageType issue and commenting out the Declare Lower statement should display the indicator on your phone, at least that is what I'm hoping :)

If you delete the hashtag I put in front of the Declare Lower statement, you should be able to view the indicator in TOS Desktop as a lower study. If you have a screen-capture program, could you capture what you're looking at...it would be a big help on this end to be able to see the issues you're having. That said, hopefully everything will be working properly negating the need for any further speculative efforts...

Code:
#declare lower;

script normalized {
    input data   = close;
    input Min    = 0;
    input Max    = 100;
    input length = 50;
    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);
    plot resized = (((Max - Min) * (data - llData)) /
                       (hhData - llData)) + Min;
}

### Relative Strength Index (RSI) ###

input length = 14;
input price = close;
def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot x = normalized(RSI);
x.SetDefaultColor(Color.GREEN);
x.SetLineWeight(3);



### True Strength Index (TSI) ###

input longLength = 25;
input shortLength = 13;
#input signalLength = 8;
input averageType2 = AverageType.EXPONENTIAL;

def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diff), longLength), shortLength);

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

plot y = normalized(TSI);
y.SetDefaultColor(Color.RED);
y.SetLineWeight(3);

Hope this helps!

Good Luck and Good Trading :cool:
Thank you very much for your help. I watched the indicator today and it performed EXACTLY the way I thought it would. I really appreciate you taking time to help!
 
Can someone help me combine RSI and TrueStrengthIndex into one indicator? I tried to copy/paste into Think Script, but it does not work. I am seeing where RSI crosses above TrueStrengthIndex for an intraday play indicates a call. The opposite is true when RSI crosses below TrueStrengthIndex, this indicated a put. I can put them on the same line in the desktop application, but the mobile version does not allow two indicators to overlap. That is my inspiration to combine them into one indicator that IOS recognizes.
Go to one of your stocks on think or swim using your phone. Tap left side until vertical box appears showing multiple items. Click candle at top left and RSI settings wheel appears. Click on settings wheel. Click on add/edit studies and add what you need.
 
Can someone help me combine RSI and TrueStrengthIndex into one indicator? I tried to copy/paste into Think Script, but it does not work. I am seeing where RSI crosses above TrueStrengthIndex for an intraday play indicates a call. The opposite is true when RSI crosses below TrueStrengthIndex, this indicated a put. I can put them on the same line in the desktop application, but the mobile version does not allow two indicators to overlap. That is my inspiration to combine them into one indicator that IOS recognizes.
What settings are u watching this on?
 
Go to one of your stocks on think or swim using your phone. Tap left side until vertical box appears showing multiple items. Click candle at top left and RSI settings wheel appears. Click on settings wheel. Click on add/edit studies and add what you need.
Thanks for the help!
 
What settings are u watching this on?
I was watching it on my desktop, where I can put two or more indicators on the same line. Mobile does not allow you to put two or more indicators on one line. netarchitech was able to help me merge the two. I was trying to use my Thinkscript editor to do this, but I was unable to figure it out.
 
@Nich76 @jay2 : I tried adding alerts, labels and arrows to the RSI-TSI indicator and ended up with a couple of issues needing further work. Unfortunately, the arrows are not plotting properly when switching timeframes and the labels are less than ideally placed. As for the alerts, they seem to be working properly :)

I'm hoping one of the following uTS members and resident Code Wizards, such as @Pensar @halcyonguy @Svanoy @SleepyZ @Joshua (my apologies to others I didn't include) might take a look and possibly offer a potential solution to the arrow plotting issue and/or the label code. Below is the latest code for the indicator and two screenshots illustrating the issues aforementioned.

b.png


c.png


Code:
declare lower;

def na = Double.NaN;

script normalizer {
    input data   = close;
    input Min    = 0;
    input Max    = 100;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### Relative Strength Index (RSI) ###

input length = 14;
input price = close;
def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot x = normalizer(RSI);
x.SetDefaultColor(Color.GREEN);
x.SetLineWeight(3);


### True Strength Index (TSI) ###

input longLength = 25;
input shortLength = 13;
input averageType2 = AverageType.EXPONENTIAL;

def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType2, MovingAverage(averageType2, AbsValue(diff), longLength), shortLength);

def TSI;

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

plot y = normalizer(TSI);
y.SetDefaultColor(Color.RED);
y.SetLineWeight(3);


def RSICrossAbove = x > y and y < y[1];
def RSICrossBelow = x < y and y > y[1];

AddLabel(yes, "RSI crossed above TSI" , if RSICrossAbove then Color.LIGHT_GREEN else Color.BLACK);
AddLabel(yes, "RSI crossed below TSI" , if RSICrossBelow then Color.PINK else Color.BLACK);

Alert(RSICrossAbove, "RSI crossed above TSI" , Alert.BAR, Sound.Chimes);
Alert(RSICrossBelow, "RSI crossed below TSI" , Alert.BAR, Sound.Chimes);

AddCloud(x,  y,  Color.GREEN,  Color.RED);

# Arrow Snippet courtesy of @lucprokop and @Pensar
# Source: https://usethinkscript.com/threads/offset-plotted-arrows-for-thinkorswim.9195/post-84956

# check if RSI has crossed TSI
def x1u = (x crosses above y);
def x1d = (x crosses below y);

input arrow_size = 4;
input arrow_vertical_factor = 10;
def vert = (ticksize() * arrow_vertical_factor * arrow_size);

# calc vertical placement for arrows
def arrow1up = if !x1u then na else low - 20 * ATR(length = 20, averageType = averageType.SIMPLE);
def arrow1dwn = if !x1d then na else high - 5 * ATR(length = 20, averageType = averageType.SIMPLE);

# plot arrows for crossings
plot pma1xup = if RSICrossAbove then arrow1up else na;
pma1xup.SetPaintingStrategy(PaintingStrategy.ARROW_up);
pma1xup.SetDefaultColor(Color.YELLOW);
pma1xup.hidebubble();
pma1xup.setlineweight(arrow_size);

plot pma1xdwn = if RSICrossBelow then arrow1dwn else na;
pma1xdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
pma1xdwn.SetDefaultColor(Color.YELLOW);
pma1xdwn.hidebubble();
pma1xdwn.setlineweight(arrow_size);

Good Luck and Good Trading :cool:
 
@netarchitech
You are using 'arrow1up' and 'arrow1dn' to plot your arrows. Those variables are assigned values, so the arrows plot at those values. Try either switching to a boolean arrow painting strategy or changing 'arrow1up' and 'arrow1dn' to 'y'.

As for the label, I assume you want it to be on the upper left corner. Use an if statement to show or hide each label. If x is above y then show only the first label, if x is below y then only show the second label.

I'm not home at the moment to write everything out as code, but I think you understand.
 
@Svanoy : Thanks for your time, the swift response and the assistance/suggestions to resolve the issues...I really appreciate it!

I think I do understand...I'll give it a go and report back here with any updates/developments...
 
Can someone help me combine RSI and TrueStrengthIndex into one indicator? I tried to copy/paste into Think Script, but it does not work. I am seeing where RSI crosses above TrueStrengthIndex for an intraday play indicates a call. The opposite is true when RSI crosses below TrueStrengthIndex, this indicated a put. I can put them on the same line in the desktop application, but the mobile version does not allow two indicators to overlap. That is my inspiration to combine them into one indicator that IOS recognizes.
I am not exactly sure how TSI works but the combined study of RSI-TSI created by @netarchitech works very similar to the RSI crossover study by @horserider and even the plots are same if the inputs are similar. I wonder if we need both studies on a chart or they are basically the same thing. Thanks @netarchitech for creating this study.
 
@Svanoy : I would like to think i understand, but, unfortunately, I don't...I spent the day working on 5 different approaches and, in the end, I failed to produce an acceptable solution to the arrow problem...I would be very interested to see your solution, if time and circumstance permit...
 
@ganq : Thanks for the "heads up"...I certainly agree with you, there is no need to have two very similar studies on your charts...

I looked for the RSI Crossover...I found the Ultimate RSI Indicator by @horserider, but failed to see a similarity...Could you post a link so I can take a look at the RSI Crossover? Thanks!
 
Last edited:
@netarchitech
The AddLabel lines would be.
Ruby:
AddLabel(if x>y then yes else no, "RSI crossed above TSI" , Color.LIGHT_GREEN);
AddLabel(If x<y then yes else no, "RSI crossed below TSI" , Color.PINK);

As for the arrow plots, I missed the "when switching timeframes" in your post. Could you clarify the issue and where you want the arrows to plot?

Also, I question these two lines.
Ruby:
def RSICrossAbove = x > y and y < y[1];
def RSICrossBelow = x < y and y > y[1];
Why have 'y<y[1]' and 'y>y[1]'?
 
@ganq : Thanks for the "heads up"...I certainly agree with you, there is no need to have two very similar studies on your charts...

I looked for the RSI Crossover...I found the Ultimate RSI Indicator by @horserider, but failed to see a similarity...Could you post a link so I can take a look at the RSI Crossover? Thanks!
I tried searching through my bookmarks but couldn’t find it. You are correct, it’s not the Ultimate RSI. I just have the indicator saved as “horserider”. One change I did do to your RSI-TSI is to make the RSI Moving Average an input and I am using “Hull” which is same as my other study. Will look around to see if I can find the post somewhere.

Edit 1: I stand corrected, it’s the Ultimate RSI:

https://usethinkscript.com/threads/ultimate-rsi-indicator-for-thinkorswim.411/

If you look at Horserider’s first post picture, it’s the 3rd lower study which I am using. Hope that helps.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
138 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