RSI Format, Label, Watchlist, Scan For ThinkOrSwim

Ruby:
AddLabel(yes, "RSI: " + rsi, if rsi > rsi[1] then Color.GREEN else if rsi < rsi[1] then Color.RED else Color.GRAY);
 
is there a way to modify it to show the 1hr RSI....on all my charts? I did something similar for ATR chart label.

i did this but the value is not coming up correctly

input BasePeriod = AggregationPeriod.HOUR;
input showlabel = yes;

def rsi = reference RSI("over bought" = 70, "over sold" = 30, price = close(period = AggregationPeriod.FOUR_DAYS));

AddLabel(yes, (Concat("RSI: ", Round(rsi, 2))), if rsi >= 70 then Color.RED else if rsi <= 30 then Color.GREEN else Color.WHITE);
Thanks script works great!!!
 
As is, it only shows RSI rising if above 50 and RSI falling if below 50. Thats only half the story. If it goes from 70 to 60, its still above 50 so shows RSI rising. Possible to have it show for example of RSI rising, it be above 50 and higher than 3 candles before? Same with RSI falling, below 50 and rsi higher 3 candles before?
input n = 21;
def RSI_ = RSI(14, 70, 30, close, AverageType.WILDERS);
def RSIUP = RSI_ > 50 and RSI_ > RSI_[1];
def RSIDN = RSI_ < 50 and RSI_ < RSI_[1];
addlabel(1, "RSI : " + Round(RSI_,2) + (if RSIUP then " RISING"
else if RSIDN then " FALLING"
else " NEUTRAL"),
if RSIUP then Color.GREEN else if RSIDN then Color.RED else Color.YELLOW);
 
here is a study to check what you mentioned at the end of your post.

RSI rising
....RSI above 50 and higher than all 3 previous candles
RSI falling
....RSI below 50 and lower than all 3 previous candles

this doesn't test if the previous RSI values were increasing, each higher than the previous.

i reduced the elements of the rules into the simplest formulas, so that they could be combined into other conditions. ( like above 50 and dropping)
i like to copy the referenced code into a study, if it isn't too many lines.

Ruby:
# RSIrangelabel_01
# ---------------------
# halcyonguy
# 21-06-16
#
# ---- study rules ----
# RSI rising,
#   RSI above 50 and higher than all 3 prev candles
# RSI falling,
#   RSI below 50 and lower than all 3 prev candles
# -----------------------------------------


# ----------------------------------------
# copy relevant RSI code from TD study
# RSI
input length = 21;
input price = close;
input 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);
# -----------------------------

def mid = 50;

def RSIabove = (RSI_ > mid);
def RSIbelow = (RSI_ < mid);

input compare_prev_bars = 3;
def rsihighest = highest(rsi_[1], compare_prev_bars);
def rsilowest = lowest(rsi_[1], compare_prev_bars);

def rsihigherprev = ( rsi_ > rsihighest );
def rsilowerprev = ( rsi_ < rsilowest );

def rsiup = rsiabove and rsihigherprev;
def RSIdn = rsibelow and rsilowerprev;

addlabel(1, "RSI : " + Round(RSI_,2) + (if RSIUP then " RISING"
else if RSIDN then " FALLING"
else " NEUTRAL"),
if RSIUP then Color.GREEN else if RSIDN then Color.RED else Color.YELLOW);


# --------------------------------
# test data
input show_hi_low_label = no;
addlabel(show_hi_low_label , "highest " + rsihighest + " lowest " + rsilowest , color.yellow);
addlabel(show_hi_low_label , rsi_ , color.yellow);

#
 
Last edited:
in the previous version, RSI rising could be when past RSI values were moving up and down, and still be less than the current RSI value.

in this version ( v02) , for it to be RSI rising, each RSI within the past x bars , has be be bigger than the previous. ( and vice versa for falling) default of x is , compare_prev_bars = 3
instead of using static code like this to detect just 1 quantity series of increasing values, x[0] > x[1] and x[1] > x[2] and ....
i used a fold loop, so it can work with any quantity of 'compare_prev_bars'

there are several options for turning on test data ( labels, arrows, numbers )
testing, 6/16 , extended hours on, WING 30min chart, shows RSI falling , after hours

Ruby:
#  RSIrangelabel_02

# -----------------------------------------
# halcyonguy
# 21-06-16
# v02 , checks series of RSI values, to see if prev is < next ,  or the opposite


# ---- study rules ----
# RSI rising,
# ....RSI above 50
# ....AND for the previous x RSI values, the previous value is < the next. a series of increasing values
# ......option to show arrows when this happens
#
# RSI falling,
# ....RSI below 50
# ....AND for the previous x RSI values, the previous value is > the next. a series of decreasing values
# ......option to show arrows when this happens

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

def na = double.nan;

# ----------------------------------------
# copy relevent RSI code from TD study
# RSI
input length = 21;
input price = close;
input 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);
# -----------------------------


def mid = 50;

def RSIabove = (RSI_ > mid);
def RSIbelow = (RSI_ < mid);

input compare_prev_bars = 3;

# check if the prev x bars had increasing values
# count each RSI that is bigger than the previous
def upcnt = fold i = 0 to compare_prev_bars
with p
do p + ( if getvalue(rsi_, i) > getvalue(rsi_, i+1) then 1 else 0 );
#  if the fold number matches compare_prev_bars, then all the bars are increasing
def upmatch = ( upcnt == compare_prev_bars);

# check if the prev x bars had decreasing values
# count each RSI that is smaller than the previous
def dwncnt = fold k = 0 to compare_prev_bars
with q
do q + ( if getvalue(rsi_, k) < getvalue(rsi_, k+1) then 1 else 0 );
#  if the fold number matches compare_prev_bars, then all the bars are decreasing
def dwnmatch = ( dwncnt == compare_prev_bars);

def rsihighest = highest(rsi_[1], compare_prev_bars);
def rsilowest = lowest(rsi_[1], compare_prev_bars);

def rsihigherprev = ( rsi_ > rsihighest and upmatch);
def rsilowerprev = ( rsi_ < rsilowest and dwnmatch);

def rsiup = rsiabove and rsihigherprev;
def RSIdn = rsibelow and rsilowerprev;

addlabel(1, "RSI : " + Round(RSI_, 2) + (if RSIUP then " RISING"
else if RSIDN then " FALLING"
else " NEUTRAL") + (" over " + compare_prev_bars + " bars"),
if RSIUP then Color.GREEN else if RSIDN then Color.RED else Color.YELLOW);


# --------------------------------
# test data
input arrows_incr_or_decr_series_of_RSI = yes;

plot upmatch2 = if arrows_incr_or_decr_series_of_RSI then upmatch else na;
upmatch2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upmatch2.SetDefaultColor(Color.white);

plot dwnmatch2 = if arrows_incr_or_decr_series_of_RSI then dwnmatch else na;
dwnmatch2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
dwnmatch2.SetDefaultColor(Color.white);

input show_hi_low_label = no;
addlabel(show_hi_low_label , "highest " + rsihighest + " lowest " + rsilowest , color.yellow);

addlabel(show_hi_low_label, "upcnt " + upcnt + " / prevbar " + compare_prev_bars, if upmatch then color.green else color.magenta);

input show_rsi_values_below_candles = no;
plot rsival = if show_rsi_values_below_candles then rsi_ else na;
rsival.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
#
 
Last edited:
Basic Red Green
Ruby:
def rsi = reference RSI()."RSI" ;
AddLabel(rsi crosses below 35 or rsi crosses above 65,
      if rsi crosses below 35 then "Buy"  else
      if rsi crosses above 65 then "Sell" else " ",
      if rsi crosses below 35 then color.green else
      if rsi crosses above 65 then color.red   else color.gray);

Alert( rsi crosses below 35, "Buy" , Alert.Bar, Sound.Bell);
Alert( rsi crosses above 65, "Sell" , Alert.Bar, Sound.Bell);
 
Last edited:
Thank you very much for a great start, I think I added inputs correctly in case I want to change it for a different stock. Does this look right?

Ruby:
input below = 35;
input above = 65;

def rsi = reference RSI()."RSI" ;
AddLabel(rsi crosses below (below) or rsi crosses above (above),
      if rsi crosses below (below) then "Buy"  else
      if rsi crosses above (above) then "Sell" else " ",
      if rsi crosses below (below) then color.green else
      if rsi crosses above (above) then color.red   else color.gray);

Alert( rsi crosses below (below), "Buy" , Alert.Bar, Sound.Bell);
Alert( rsi crosses above (above), "Sell" , Alert.Bar, Sound.Bell);
 
Hello, I was looking for an RSI label posted on chart with the RSI number as it's moving. Doesn't have to change colors or give buy or sell. Yellow lable would be nice. I don't have coding experience, but checking out this post and looking to see if I can create one. Any help would be appreciated. From that code, I could probably figure out how to make other labels stay on my charts. Top left.
 
Last edited by a moderator:
Hello, I was looking for an RSI label posted on chart with the RSI number as it's moving. Doesn't have to change colors or give buy or sell. Yellow lable would be nice. I don't have coding experience, but checking out this post and looking to see if I can create one. Any help would be appreciated. From that code, I could probably figure out how to make other labels stay on my charts. Top left.

Here you go...

Ruby:
#RSI_Label

input showRSI = yes;
input rsiLength = 14;
input rsiOverBought = 70;
input rsiOverSold = 30;
input rsiPrice = close;
input rsiAverageType = AverageType.WILDERS;
input rsiShowBreakouts = no;

def rsi = Round(RSI(rsiLength, rsiOverBought, rsiOverSold, rsiPrice, rsiAverageType), 0);

#AddLabel(showRSI, "RSI: " + rsi, if rsi < rsiOverSold then Color.CYAN else if rsi > rsiOverBought then Color.LIGHT_RED else Color.WHITE);

AddLabel(showRSI, "RSI: " + rsi, Color.YELLOW
 
Okay how would I take this a step further where above the 50 is green below the 50 is red and both overbought and oversold are yellow. It only gives you options for normal, overbought and oversold
 
RSI upper study -- RSI only signals when price is below SMA100
Shared Link: http://tos.mx/My1Svv3
Click here for --> Easiest way to load shared links
1RB2hhS.png

Ruby:
#RSI Indicator w/ arrows, label, & alerts when price is below SMA100
input OB = 65;
input OS = 35;
input rsi_length = 14 ;
input showLabel = yes ;

def rsi = reference RSI("length" = 14)."RSI" ;
plot avg100 = MovingAverage(AverageType.SIMPLE, close, 100);
avg100.SetDefaultColor(color.violet);

plot UpArrow = 
if  rsi   is less than OS and 
    close is less than avg100 then low else double.NaN ;
UpArrow .SetPaintingStrategy(PaintingStrategy.ARROW_up);
UpArrow .SetLineWeight(1);
UpArrow .SetDefaultColor(color.blue) ;

plot DownArrow = if  rsi > OB then high else double.NaN ;
DownArrow  .SetPaintingStrategy(PaintingStrategy.ARROW_down);
DownArrow  .SetLineWeight(1);
DownArrow  .SetDefaultColor(color.magenta) ;

AddLabel(showLabel,
      if rsi   is less than OS and 
         close is less than avg100 then "Buy"  else
      if rsi > OB then "Sell" else "RSI: " +round(rsi,1),
      if rsi   is less than OS and 
         close is less than avg100 then color.green else
      if rsi > OB then color.red   else color.gray);

Alert( rsi   is less than OS and 
       close is less than avg100, "Buy" , Alert.Bar, Sound.Bell);
Alert( rsi > OB , "Sell" , Alert.Bar, Sound.Bell);
Per @tem2005 request:
https://usethinkscript.com/threads/request-to-convert-tv-high-success-rate.7328/#post-70780
 
Hey Im trying to Input some Letters "OB" "OS" on the RSI any help?

Code:
def rsiAbove = RSI()."RSI" is greater than RSI()."OverBought" ;
def rsiBelow = RSI()."RSI" is less than RSI()."OverSold";
plot value = if rsiAbove then 1 else if rsiBelow then -1 else 0;
Assignbackgroundcolor(if value == 1 then Color.Orange else if value == -1 then color.Green else color.current);
value.assignValuecolor(if value == 0 then color.current else color.black);
 
This is for a watchlist. I tried add label but not working

Thanks for clarifying... Here is one example...

Ruby:
def rsiAbove = RSI()."RSI" is greater than RSI()."OverBought" ;
def rsiBelow = RSI()."RSI" is less than RSI()."OverSold";

plot value = if rsiAbove then 1 else if rsiBelow then -1 else 0;
value.Hide();

AddLabel(yes, if value == 1 then "OB" else if value == -1 then "OS" else " ", Color.BLACK);

AssignBackgroundColor(if value == 1 then Color.Orange else if value == -1 then color.Green else color.current);
 
@Branch Here is a simple label that compares two RSI values and displays whether the RSI is RISING or FALLING over n periods
I have color coded the label green, pink, and yellow

Code:
input n = 21;
def RSI_ = RSI(14, 70, 30, close, AverageType.WILDERS);
def RSIUP = RSI_ > RSI_[n];
def RSIDN = RSI_ < RSI_[n];
addlabel(1, "RSI : " + Round(RSI_,2) + (if RSIUP then " RISING [" + n + " BARS]"
                                        else if RSIDN then " FALLING [" + n + " BARS]"
                                        else " NEUTRAL"),
if RSIUP then Color.GREEN else if RSIDN then Color.PINK else Color.YELLOW);
This code is just what I was looking for to display a badge/label on my chart.
Is there any way to turn this into a scan? Where the scan will look for a rising over the past 21 bars?
Thanks!!
 
Give this a try:

Code:
def rsi = RSIWilder("over bought" = 95, "over sold" = 5, price = close(period = AggregationPeriod.FOUR_DAYS));
AddLabel(yes, rsi, if rsi >= 95 or rsi <= 5 then Color.RED else Color.WHITE);

Source
Hi Ben, how can we move the bubble to the right of the chart?
also how to add bubble on a line? Thanks,
 
Hi Ben, how can we move the bubble to the right of the chart?
also how to add bubble on a line? Thanks,
This is a lower study that you can move to the upper price pane, uncheck enable left axis, and choose whether to show or not the label and/or bubble. You can move the bubble sideways and or up and down. You can hide the plots that are necessary by setting their color to that of the chart background.
Capture.jpg
Ruby:
input agg        = AggregationPeriod.FOUR_DAYS;
input showlabel  = yes;
input showbubble = yes;
def rsi = reference RSI("over bought" = 95, "over sold" = 5, price = close(period = agg));
AddLabel(showlabel, rsi, if rsi >= 95 or rsi <= 5 then Color.RED else Color.WHITE);

declare lower;

plot  top         = 100;
plot  bottom      = 0;
top.SetDefaultColor(Color.GRAY);
bottom.SetDefaultColor(Color.GRAY);

input bubblemover_sideways = 5;
input bubblemover_updown   = 0;
def   b   = bubblemover_sideways;
def   b1  = b + 1;
AddChartBubble(showbubble and IsNaN(close[b]) and !IsNaN(close[b1]), top[b] + bubblemover_updown, rsi[b1], if rsi[b1] >= 95 or rsi[b1] <= 5 then Color.RED else Color.WHITE, no);
 
this code turns the label green then prints bullish or bearish when rsi is less than or greater than 50

i would like the label to print bullish then turn green or print bearish then turn red.


def trendsignals = 50;
plot trend = trendsignals;
trend.SetLineWeight(2);
trend.HideBubble();
trend.HideTitle();
trend.SetDefaultColor(GetColor(7));

def na = Double.NaN;
plot label_color = na;
label_color.SetDefaultColor(GetColor(6));

input show_rsi_label = yes;
AddLabel(show_rsi_label, if RSI > trend then "RSI TREND: >50" + "BULLISH" else "RSI TREND: <50" + "BEARISH", label_color.TakeValueColor());
 
Here is my RSI label script. Feel free to modify it as you wish, or use ideas from it for your task.
Code:
##### Begin Code #####

# SD_RSILabel
# Scott D#####
# Version: 05
# Original: November 14, 2020
# Last Mod: December 14, 2020

declare upper;

input length = 14;
input RSIOverbought = 70;
input RSIOversold = 30;
input RSIPos = 60;
input RSINeg = 40;
input median = 50;
input RSI_to_Median = yes;
input RSI_Warning = yes;
input Spacer = yes;
# input AlertHiLevel = 70;
# input AlertLoLevel = 30;

def RSIlabel = reference RSI(length,price = close);

#spacer
addlabel(Spacer, "          ", color.BLACK);

AddLabel(yes, if RSIlabel > RSIlabel[1] then "                           RSI RISING                           " else "                          RSI FALLING                         ", if RSIlabel > RSIlabel[1] then Color.GREEN else Color.RED);

AddLabel(yes, if RSIlabel >= RSIOverbought then "                    RSI OVERBOUGHT                    " else "", Color.RED);

AddLabel(yes, if RSIlabel <= RSIOversold then "                       RSI OVERSOLD                       " else "", Color.GREEN);

AddLabel(RSI_Warning, if RSIlabel >= RSIPos then "                RSI HIGH WARNING                " else "", Color.RED);

AddLabel(RSI_Warning, if RSIlabel <= RSINeg then "                RSI LOW WARNING                " else "", Color.GREEN);

AddLabel(RSI_to_Median, " RSI TO MEDIAN " + Round(RSILabel,0) + " ", if RSIlabel > median then Color.LIME else if RSIlabel <= median then Color.ORANGE else Color.WHITE);

# Alert(RSILabel > AlertHiLevel, "", Alert.Bar, Sound.Ring);
# Alert(RSILabel < AlertLoLevel, "", Alert.Bar, Sound.Ring);

##### End Code #####
 
Can anyone help me create a script when stock falls below 30 I don't need alert that time when it comes up to RSi 32 I need alert.
If any one create much appreciated. Actually I created but I don't know if this is correct.

"RSI()."RSI" is less than 30 within 15 bars and RSI()."RSI" is greater than 32 ;
 

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