RSI Format, Label, Watchlist, Scan For ThinkOrSwim

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?

Try this

Ruby:
AddLabel(1, "RSI " + Round(RSI()), if RSI() > 70 then Color.GREEN else if RSI() < 30 then Color.RED else Color.YELLOW);
 
Last edited by a moderator:
Hello everyone, Is there a way to add a label that only prints on the candle close? Im trying to add a Label that turns green on a buy order but I only want it to turn green once the candle closes and that price is locked in. Right now I get the label to turn green but the price can go up and down and make the buy signal flash.

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddLabel(yes, "BUY ", if rsi < over_sold then Color.GREEN else Color.WHITE);
AddLabel(yes, "SELL ", if rsi > over_bought then Color.RED else Color.WHITE);

The problem is when the RSI crosses above the "Over_Sold" positon multiple times in 1 candle? then closes below it?
 
Last edited by a moderator:
@aCuddlyTurtle
read more about:
Ruby:
declare once_per_bar;
https://tlc.thinkorswim.com/center/reference/thinkScript/Declarations/once-per-bar

Here is the complete code:
Ruby:
declare once_per_bar;
input price = close;
input length = 14;
input OB = 70;
input OS = 30;
input rsiAverageType = AverageType.WILDERS;

def over_bought= OB;
def over_sold = OS ;
def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddLabel(yes, "BUY ", if rsi crosses above over_sold then Color.GREEN else Color.WHITE);
AddLabel(yes, "SELL ", if rsi crosses below over_bought then Color.RED else Color.WHITE);
 
Last edited:
Hello everyone, Is there a way to add a label that only prints on the candle close? Im trying to add a Label that turns green on a buy order but I only want it to turn green once the candle closes and that price is locked in. Right now I get the label to turn green but the price can go up and down and make the buy signal flash.

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddLabel(yes, "BUY ", if rsi < over_sold then Color.GREEN else Color.WHITE);
AddLabel(yes, "SELL ", if rsi > over_bought then Color.RED else Color.WHITE);
what indicator are you using?
 
Last edited by a moderator:
EDIT: Okay i fixed it. Its a label that changes green or red color intensity based on 10 different colors. Was missing parenthesis around the body of if statements. I added the fixed code in the code box. I haven't fully tweaked the colors yet though so that may take some testing.

---------------------------------------------------------------------
OLD:
I'm having trouble getting this code to function. I seem to only be able to get 2 colors to show no matter the actual RSI value. I think only the first and the last will show, "green1" and "color.green". Anyone see what i'm doing wrong?


Code:
input length = 14;
input overBought = 70;
input overSold = 30;
input averageType = AverageType.WILDERS;
input price = close;

DefineGlobalColor("green1", CreateColor(175, 220, 175)) ;
DefineGlobalColor("green3", CreateColor(90, 220, 90)) ;
DefineGlobalColor("green4", CreateColor(50, 150, 50)) ;
DefineGlobalColor("red1", CreateColor(225, 125, 125)) ;
DefineGlobalColor("red2", CreateColor(200, 75, 75)) ;
DefineGlobalColor("red3", CreateColor(150, 50, 50)) ;

def RSI = Round(RSI(length, overBought, overSold, price, averageType), 2);

AddLabel(1, "RSI " + RSI,(
if RSI between 50.01 and 60 then createcolor(175, 220, 175) else
if RSI between 40.01 and 50 then Color.PINK else
if RSI between 60.01 and 70 then Color.LIGHT_GREEN else
if RSI between 30.01 and 40 then CreateColor(225, 125, 125) else
if RSI between 70.01 and 80 then CreateColor(90, 220, 90) else
if RSI between 20.01 and 30 then CreateColor(200, 50, 50) else
if RSI between 10.01 and 20 then CreateColor(150, 50, 50) else
if RSI < 10 then Color.RED else
if RSI between 80 and 90 then CreateColor(50, 150, 50) else
Color.GREEN));
 
Last edited:
#Basic RSI Indicator With Arrows, Label, & Alerts
cCnrv0g.png

Shared Link: http://tos.mx/vYwKbJ5
Click here for --> Easiest way to load shared links
Ruby:
#Basic RSI Indicator w/ arrows, label, & alerts
input OB = 70;
input OS = 30;
input rsi_length = 14 ;
input showLabel = yes ;

def rsi = reference RSI("length" = 14)."RSI" ;

plot UpArrow = if  rsi crosses above OS  then low else double.NaN ;
UpArrow .SetPaintingStrategy(PaintingStrategy.ARROW_up);
UpArrow .SetLineWeight(1);
UpArrow .SetDefaultColor(color.blue) ;

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

AddLabel(showLabel,
      if rsi crosses above OS then "Buy"  else
      if rsi crosses below OB then "Sell" else "RSI: " +round(rsi,1),
      if rsi crosses above OS then color.green else
      if rsi crosses below OB then color.red   else color.gray);

Alert( rsi crosses above OS, "Buy" , Alert.Bar, Sound.Bell);
Alert( rsi crosses below OB , "Sell" , Alert.Bar, Sound.Bell);
Is there a way to plot the price of rsi in the label instead of the rsi length?
 
Is there a way to plot the price of rsi in the label instead of the rsi length?
RSI does not have a "price".

It is a bound oscillator. It moves between 0 and 100 representing the "strength" of the price movement not the price. Which means when there is a divergence, the price could be in a downward trend and the RSI could be trending up.

The label reflects its current position.
In the example that you included in your post: RSI 58.7 would mean that the RSI was approx. at the mid-point (50) of the oscillator.
 
Thank you. Can you add the DAILY value for RSI on a label also?
Here is RSI with Daily Value
Capture.jpg
Ruby:
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input Agg = AggregationPeriod.DAY;

input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

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

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;

def rsid = if IsNaN(RSI) then rsid[1] else RSI;
AddLabel(yes, "RSIDay: " + Round(rsid), if rsid >= over_Bought then Color.GREEN else if rsid <= over_Sold then Color.RED else Color.WHITE);
 
Hello,

I'm not very good at coding and was hoping someone could help me code what should I hope be a pretty easy study.

I would like an upper indicator that paints the bars different colors based on the RSI settings. For example,

If RSI 14 is greater than 70 then paint the bars red
else
If RSI 14 less than 30 then paint the bars green
else paint the bars gray


...Full disclosure I would really like to add a second layer so I could use a 2nd RSI setting. So something like:

if RSI 100 is greater than 55
and
If RSI 14 is greater than 70 then paint the bars dark green
else
paint the bar light green

and
if RSI 100 is less than 45
and
If RSI 14 less than 30 then paint bars the dark red
else paint the bars light red

else
paint the bars Gray

So, like if RSI 100 is between 45 and 55 the bars would be gray, otherwise they should either be Dark/Light Green (the areas above RSI 100 day - 55 level) or Dark/Light Red (in the areas below RSI 100 day - 45 level). Hopefully I have explained that correctly.

Thank you for any help, and sorry if this is the wrong area for this.
 
Last edited:
Hello,

I'm not very good at coding and was hoping someone could help me code what should I hope be a pretty easy study.

I would like an upper indicator that paints the bars different colors based on the RSI settings. For example,

If RSI 14 is greater than 70 then paint the bars red
else
If RSI 14 less than 30 then paint the bars green
else paint the bars gray


...Full disclosure I would really like to add a second layer so I could use a 2nd RSI setting. So something like:

if RSI 100 is greater than 55
and
If RSI 14 is greater than 70 then paint the bars dark green
else
paint the bar light green

and
if RSI 100 is less than 45
and
If RSI 14 less than 30 then paint bars the dark red
else paint the bars light red

else
paint the bars Gray

So, like if RSI 100 is between 45 and 55 the bars would be gray, otherwise they should either be Dark/Light Green (the areas above RSI 100 day - 55 level) or Dark/Light Red (in the areas below RSI 100 day - 45 level). Hopefully I have explained that correctly.

Thank you for any help, and sorry if this is the wrong area for this.

I used the full disclosure for the 100 and reversed the colors on your first request for the rsi 14 greater to be green and lesser to be red. If this id not how you want it, you should be able to make the changes

Ruby:
def rsi14  = RSI(14);
def rsi100 = RSI(100);
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if rsi100 > 55 and rsi100 < 70 then Color.DARK_GREEN
else if rsi14 > 70 then Color.GREEN
else if rsi14 < 30 then Color.RED
else if rsi100 < 45 and rsi100 > 30 then Color.DARK_RED
else Color.GRAY
);
 
I used the full disclosure for the 100 and reversed the colors on your first request for the rsi 14 greater to be green and lesser to be red. If this id not how you want it, you should be able to make the changes
Thank you so much! That's exactly what I wanted <3
 
I was messing around with this idea and have narrowed it down to this and find it useful. Here is what I came up with. I can load instances of this into my chart after renaming them and changing the settings to desired values like 5min, 1hr and day names and saving the aggregation for each either within the code or in the configuration of each then saving. Perhaps not exactly what you wish but its as far as I am for now. Here is the RSI_MTF_Label >>

#Begin
input length = 14;
input RSIOverbought = 70.00;
input RSIOversold = 30.00;
input Ap = AggregationPeriod.five_MIN;

def RSIp = reference RSI(length, price = close(period = Ap )).RSI;

AddLabel(yes, if Ap == aggregationPeriod.YEAR then "RSI Y : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.QUARTER then "RSI Q : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.MONTH then "RSI M : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.WEEK then "RSI W: " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.FOUR_DAYS then "RSI 4D : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.THREE_DAYS then "RSI 3D : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.TWO_DAYS then "RSI 2D : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.DAY then "RSI D : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.FOUR_HOURS then "RSI 4h : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.TWO_HOURS then "RSI 2H :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.HOUR then "RSI 60m : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.THIRTY_MIN then "RSI 30m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.TWENTY_MIN then "RSI 20m : " + Round(RSIp, 2)
else
if Ap == aggregationPeriod.FIFTEEN_MIN then "RSI 15m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.TEN_MIN then "RSI 10m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.FIVE_MIN then "RSI 5m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.FOUR_MIN then "RSI 4m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.THREE_MIN then "RSI 3m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.TWO_MIN then "RSI 2m :" + Round(RSIp, 2)
else
if Ap == aggregationPeriod.MIN then "RSI 1m" + Round(RSIp, 2)
else "",

if RSIp >= RSIOverbought then Color.RED else if RSIp <= RSIOversold then Color.GREEN else Color.WHITE);

# END
 
Last edited:
Can someone please help with the solution of limiting a plotted line condition start to 10 futures bars to the right only.
it currently plots with a length until the next condition is met. A picture of the desired outcome and the code is below. Thank you in advance.



Ruby:
def RSI_length = 14;
def RSI_price = close;
def RSI_averageType = AverageType.WILDERS;

def RSI_NetChgAvg = MovingAverage(RSI_averageType, RSI_price - RSI_price[1], RSI_length);
def RSI_TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_price - RSI_price[1]), RSI_length);
def RSI_ChgRatio  = if RSI_TotChgAvg != 0 then RSI_NetChgAvg / RSI_TotChgAvg else 0;

def RSI = 50 * (RSI_ChgRatio + 1);
def RSI_Below =   RSI > 50  ;

def RSI_COND = if RSI_Below  and !RSI_Below[1] then close else RSI_COND[1];
plot RSI_p = if  RSI_COND  then RSI_COND  else double.NaN;
RSI_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RSI_p.SetDefaultColor(color.yellow);

TZ.png
 
Last edited by a moderator:
Can someone please help with the solution of limiting a plotted line condition start to 10 futures bars to the right only.
it currently plots with a length until the next condition is met. A picture of the desired outcome and the code is below. Thank you in advance.



Ruby:
def RSI_length = 14;
def RSI_price = close;
def RSI_averageType = AverageType.WILDERS;

def RSI_NetChgAvg = MovingAverage(RSI_averageType, RSI_price - RSI_price[1], RSI_length);
def RSI_TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_price - RSI_price[1]), RSI_length);
def RSI_ChgRatio  = if RSI_TotChgAvg != 0 then RSI_NetChgAvg / RSI_TotChgAvg else 0;

def RSI = 50 * (RSI_ChgRatio + 1);
def RSI_Below =   RSI > 50  ;

def RSI_COND = if RSI_Below  and !RSI_Below[1] then close else RSI_COND[1];
plot RSI_p = if  RSI_COND  then RSI_COND  else double.NaN;
RSI_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RSI_p.SetDefaultColor(color.yellow);
TZ.png

This should limit the plot to the value of input plot_limiter

Screenshot-2022-10-15-121626.png
Ruby:
input plot_limiter = 10;
def RSI_length = 14;
def RSI_price = close;
def RSI_averageType = AverageType.WILDERS;

def RSI_NetChgAvg = MovingAverage(RSI_averageType, RSI_price - RSI_price[1], RSI_length);
def RSI_TotChgAvg = MovingAverage(RSI_averageType, AbsValue(RSI_price - RSI_price[1]), RSI_length);
def RSI_ChgRatio  = if RSI_TotChgAvg != 0 then RSI_NetChgAvg / RSI_TotChgAvg else 0;

def RSI = 50 * (RSI_ChgRatio + 1);
def RSI_Below =   RSI > 50  ;

def RSI_COND = if RSI_Below  and !RSI_Below[1] then close else RSI_COND[1];
def rsi_ct = if RSI_Below  and !RSI_Below[1] then 1 else rsi_ct[1] + 1;
plot RSI_p = if  rsi_ct <= plot_limiter  then RSI_COND  else Double.NaN;
RSI_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RSI_p.SetDefaultColor(Color.YELLOW);
 
input Period = AggregationPeriod.DAY;
def PC = close(period = AggregationPeriod.DAY)[1];
def PctChange = (close - PC) / PC;

AddLabel(1, "%Chg = " + AsPercent(PctChange), if PctChange > 0 then Color.GREEN else if PctChange < 0 then Color.RED else Color.GRAY);
# End Percent Change Label (from Yesterday's Close)

input length = 14;
input over_Bought = 70;
input over_Sold = 30;

#n = length;
def RSI = RSI(length, over_Bought , over_Sold , close, AverageType.WILDERS);
input price = close;

AddLabel(1, "RSI = " + RSI, if RSI > over_bought then Color.RED else if RSI < over_sold then Color.RED else Color.GRAY);
 
@benito_3 This should work.

I modified the number sequence just so it's easier to understand.

Code:
input VLow =35;
input Low = 45;
input High = 55;
input VHigh = 65;

plot RSI = (if RSI()."RSI" is less than VLow then 1
else if RSI()."RSI" is greater than or equal to VLow and RSI()."RSI" is less than Low then 2
else if RSI()."RSI" is greater than or equal to Low and RSI()."RSI" is less than High then 3
else if RSI()."RSI" is greater than or equal to High and RSI()."RSI" is less than VHigh then 4
else 5);

AssignBackgroundColor(if RSI equals 1 then Color.RED
else if RSI equals 2 then Color.LIGHT_RED
else if RSI equals 3 then Color.DARK_GRAY
else if RSI equals 4 then Color.GREEN
else if RSI == 5 then Color.DARK_GREEN else color.gray);
How can I change the color of the numbers. They are white and hard to see with the light colors. I tried to change it but couldn't figure it out. Thank you!
 

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