RSI Format, Label, Watchlist, Scan For ThinkOrSwim

I had to change

plot Normal = RSI > OverSold and RSI < OverSold;

to

plot Normal = RSI > OverSold and RSI < OverBought;

But otherwise, this is exactly what I needed. Thanks again!!
 
The following code is a TOS stock code for RSI. By default, an arrow is plotted when the rsi < over_bought and also when the rsi > over_sold. What I have been racking my brain to figure out how to plot an arrow, or point(doesnt matter) when rsi = rsi. In other word, when it is neither overbought nor oversold. In other words, the text that is bolded below. I've tried everything. Is there anyone that can help me with this?

programming is about using formulas to evaluate numbers.
if you want something different to happen, try to think of which variables and/or numbers to compare to to make it happen.

if you want to do something when rsi is neither overbought nor oversold, then rsi has a value between them.
for reference, the default values,
input over_Bought = 70;
input over_Sold = 30;


the easiest thing would be to set this built in setting to yes.
input showBreakoutSignals = no
then you will have an arrow on the first bar that rsi enters the 'normal' price range.


you could have created a formula to determine when rsi is in your desired range.
then use that variable to trigger something to happen on the chart.
def normal = if rsi < over_Bought and rsi > over_Sold then 1 else 0;

like moxiesmiley did, but use def instead of plot.
there is no reason to plot a boolean value on a chart with other values. the values, 0 or 1, are so small compared to the other values on the chart, that the changes can barely be seen. and it shifts the main plot, reducing its size.


instead of plotting the variable normal, use it to enable a row of points or some shading between 30 and 70, like in this version.

Ruby:
# rsi_normal_zone

# RSI
# TD Ameritrade IP Company, Inc. (c) 2007-2022
declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

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;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#-------------------------------------------

# copy original RSI and add this

def na = double.nan;
#  add points at 50 , for normal zone
def normal = if rsi < over_Bought and rsi > over_Sold then 1 else 0;

input show_points_when_normal = yes;
plot p = if normal then 50 else na;
p.SetPaintingStrategy(PaintingStrategy.POINTS);
p.SetDefaultColor(Color.cyan);
p.setlineweight(2);
p.hidebubble();

#  add shading when rsi is in normal zone
input show_shading_when_normal = yes;
def cloudtop = if normal then over_Bought else na;
def cloudbot = if normal then over_sold else na;
addcloud(cloudtop, cloudbot, color.gray, color.gray);
#


this shows both of these set to yes
input show_points_when_normal = yes;
input show_shading_when_normal = yes;
dpEYZf2.jpg
 
anyway to get a addlabel as a RSI,,sometime RSI indicator doesnt fit when i have a bunch of small charts on a flexible grid,,,, if possible to turn Red when below the 50 line and Green when it is above the 50 line,,,any assistance would be greatly appreciated
 
#My_RSILabel

input RSILength = 10;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], RSILength);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), RSILength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
input over_Bought = 60;
input over_Sold = 50;
def RSI = 50 * (ChgRatio + 1);

def rsiUP = RSI > 60;
def rsiDN = RSI < 60;
def rsinet = !rsiUP and !rsiUP;
AddLabel(yes, Concat("RSI=", RSI), if rsidn then Color.RED else Color.GREEN);
 
#My_RSILabel

input RSILength = 10;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], RSILength);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), RSILength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
input over_Bought = 60;
input over_Sold = 50;
def RSI = 50 * (ChgRatio + 1);

def rsiUP = RSI > 60;
def rsiDN = RSI < 60;
def rsinet = !rsiUP and !rsiUP;
AddLabel(yes, Concat("RSI=", RSI), if rsidn then Color.RED else Color.GREEN);
Exactly what i was looking for,, cant thank you enough,,,

while i have you attention.... is there anyway to add a specific aggregation period to this code? i like to use a 15 min RSI on 3minute chart when possible,,

also are you able to code something like this for A MACD LABEL,,, when histogram and lines are above Zero line, Label turns green, when both lines and histogram are below zero line label turns green, when histogram and lines are not both above or below zero line label turns yellow,,,

your time is greatly appreciated
 
Exactly what i was looking for,, cant thank you enough,,,

while i have you attention.... is there anyway to add a specific aggregation period to this code? i like to use a 15 min RSI on 3minute chart when possible,,

also are you able to code something like this for A MACD LABEL,,, when histogram and lines are above Zero line, Label turns green, when both lines and histogram are below zero line label turns green, when histogram and lines are not both above or below zero line label turns yellow,,,

your time is greatly appreciated
It works on whichever time frame you use it on. Now if you are wanting an mtf to show on multiple time frames on same chart, that take someone smarter than me. I do not code but just take parts of scripts and add them to make what I want. I do not use the macd but will look at it this weekend if you can post script of the one you use if it matters.
 
i'm trying to figure out how to write a bit of code to do the following. let's use this variation on the basic rsi strat:


AddOrder(OrderType.BUY_AUTO, rsi crosses below 30);
AddOrder(OrderType.SELL_AUTO, rsi crosses above 70);

as it stands, on a daily chart, when rsi crosses below 30 at the close, the buy order hits the next day at the open. what i'd like to try is having the buy go off not on the open but at a price a certain percentage amount below the previous day's close. let's call it 4%. don't want to buy at the open. do want to buy at a price 4% below the previous day's close.

possible?
 
i'm trying to figure out how to write a bit of code to do the following. let's use this variation on the basic rsi strat:


AddOrder(OrderType.BUY_AUTO, rsi crosses below 30);
AddOrder(OrderType.SELL_AUTO, rsi crosses above 70);

as it stands, on a daily chart, when rsi crosses below 30 at the close, the buy order hits the next day at the open. what i'd like to try is having the buy go off not on the open but at a price a certain percentage amount below the previous day's close. let's call it 4%. don't want to buy at the open. do want to buy at a price 4% below the previous day's close.

possible?


maybe?
addorder has a price parameter.

price
default, open[-1]
Defines price at which the order is added.

try defining a formula to be the buy level you want, then reference it in the addorder.
if the current candle range doesn't include your price, not sure if it will execute. and if it does, it would be unrealistic and useless.

Code:
def lower_per = 4;
def mybuyprice = close[1] * (1 - (lower_per/100));
AddOrder( OrderType.BUY_AUTO, rsi crosses below 30, mybuyprice );

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder
 
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

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;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.Color("OverBought") else if RSI < over_Sold then RSI.Color("OverSold")
else RSI.Color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN)
I combined two RSI.
FAHFOVY.png

Ruby:
#https://usethinkscript.com/threads/rsi-format-label-watchlist-scan-for-thinkorswim.798/page-7
declare lower;
input nRSI = 2;
input OverBought = 95;
input OverSold = 5;
input MidLine = 50;
input nTrend = 100;
input TrendLine = {EMA, SMA, default LRL, WMA};
input length = 14;
input over_Bought_a = 70;
input over_Sold_a = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

# Global definitions
def h = high;
def l = low;
def c = close;

def cond1 = CompoundValue(1, if IsNaN(c)
                            then cond1[1]
                            else c, c);

def NetChgAvg = WildersAverage(c - c[1], nRSI);
def TotChgAvg = WildersAverage(AbsValue(c - c[1]), nRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = round(50 * (ChgRatio + 1),0);
RSI.SetLineWeight(3);
RSI.AssignValueColor(if RSI < OverSold then Color.Green else if  RSI > OverBought then Color.Red else Color.Gray);

plot RSItrend;
switch (TrendLine) {
case EMA:
   RSItrend = ExpAverage(RSI, nTrend);
case SMA:
   RSItrend = Average(RSI, nTrend);
case LRL:
   RSItrend = InertiaAll(RSI, nTrend);
case WMA:
   RSItrend = WMA(RSI, nTrend);
}
RSItrend.SetLineWeight(1);
RSItrend.SetDefaultColor(Color.RED);

plot RSIOB = OverBought;
RSIOB.SetLineWeight(1);
RSIOB.SetDefaultColor(Color.Blue);
plot RSIOS = OverSold;
RSIOS.SetLineWeight(1);
RSIOS.SetDefaultColor(Color.Blue);

def lowestLow = if RSI > OverSold
               then l
               else if RSI < OverSold and
                       l < lowestLow[1]
               then l
               else lowestLow[1];
def lowestRSI = if RSI > MidLine
               then RSI
               else if RSI < MidLine and
                       RSI < lowestRSI[1]
               then RSI
               else lowestRSI[1];
def divergentLow = if RSI < OverSold and
                  l <= lowestLow[1] and
                  RSI > lowestRSI[1]
                  then OverSold
                  else Double.NaN;
plot DLow = divergentLow;
DLow.SetPaintingStrategy(PaintingStrategy.POINTS);
DLow.SetLineWeight(3);
DLow.SetDefaultColor(Color.YELLOW);

def highestHigh = if RSI < OverBought
                 then h
                 else if RSI > OverBought and
                         h > highestHigh[1]
                 then h
                 else highestHigh[1];
def highestRSI = if RSI < MidLine
                then RSI
                else if RSI > MidLine and
                        RSI > highestRSI[1]
                then RSI
                else highestRSI[1];
def divergentHigh = if RSI > OverBought and
                      h >= highestHigh[1] and
                      RSI < highestRSI[1] and
                      cond1 within 3 bars
                   then OverBought
                   else Double.NaN;

plot DHigh = divergentHigh;
DHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
DHigh.SetLineWeight(3);
DHigh.SetDefaultColor(Color.YELLOW);


def NetChgAvg_a = MovingAverage(averageType, price - price[1], length);
def TotChgAvg_a = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio_a = if TotChgAvg_a != 0 then NetChgAvg_a / TotChgAvg_a else 0;

plot RSI_a = 50 * (ChgRatio_a + 1);
plot OverSold_a = over_Sold_a;
plot OverBought_a = over_Bought_a;
plot UpSignal = if RSI_a crosses above OverSold_a then OverSold_a else Double.NaN;
plot DownSignal = if RSI_a crosses below OverBought_a then OverBought_a else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI_a.DefineColor("OverBought", GetColor(5));
RSI_a.DefineColor("Normal", GetColor(8));
RSI_a.DefineColor("OverSold", GetColor(1));
RSI_a.AssignValueColor(if RSI_a > over_Bought_a then RSI_a.Color("OverBought") else if RSI_a < over_Sold_a then RSI_a.Color("OverSold") else RSI_a.Color("Normal"));
RSI_a.SetLineWeight(3);
OverSold_a.SetDefaultColor(GetColor(8));
OverBought_a.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Last edited by a moderator:
Arrow at RSI High and Low
Hello - I'm looking for a code that plots an arrow at the highest and lowest points for the day. Thanks in advance!
 
Last edited by a moderator:
Here is the image of the current RSI with Bubbles at the bottom chart. I just want the bubbles to be at the top chart at the price it crosses.
https://tos.mx/svdImGN (still trying to figure out how to insert image - it only gives me a link option)
 
Two more questions:
1 - is there a way to make the bubble show on the left side of the price instead of the right side that overlaps the next bars?
2 - is there a way to make more distance between the bubble and the price location it points to?
 
Hi everyone and happy Friday!! i was wondering if anyone knows the code to add horizontal levels in a lower indicator on TOS (Like RSI)? I am currently having to manually add them onto the indicator for every ticker I open up.
 
Hi everyone and happy Friday!! i was wondering if anyone knows the code to add horizontal levels in a lower indicator on TOS (Like RSI)? I am currently having to manually add them onto the indicator for every ticker I open up.

Copy the TOS RSI indicator code and paste it in a newly created study. Then add the levels you want to it. For example,

Code:
Plot mid     = 50;
Plot midhigh = 60;
Plot midlow  = 40;
 
Ideally I want the tag to turn RED if the RSI is over 70 and turn Green if it's under 30, else it can be white or grey. Anyone know a script that does that?
 
Last edited by a moderator:

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
297 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