RSI Format, Label, Watchlist, Scan For ThinkOrSwim

Dear all,
Need help with explanation and/or possible solution.

After moving logic from RSI study to watchlist column (preserving the same aggregation settings for chart vs watchlist column) the watchlist values are not consistent with "arrows" painting on the charts.
There are cases when arrows come and disappear immediately, while watchlist detecting and repeatedly reporting states. I tried adding condition to check last closed candle (see snipped below), but with no luck.

##########################################
# Momentum: RSI

script RSIMomentum {

input price = close;
input length = 14;
input over_bought = 60;
input over_sold = 40;
input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

def buySignal = rsi crosses above over_sold;
def sellSignal = rsi crosses below over_bought;

def lastClose = if !IsNaN(close) and IsNaN(close[-1]) then close else lastClose[1];

plot RSISignal = if (lastClose) then
(
if buySignal then 1 #Buy
else if sellSignal then -1 #Sell
else 0 #Neutral
) else Double.NaN;

#################END CODE
}

def _RSISignal = RSIMomentum().RSISignal;

AddLabel(yes, _RSISignal, COLOR.WHITE);

Thanks in advance
 
Dear all,
Need help with explanation and/or possible solution.

After moving logic from RSI study to watchlist column (preserving the same aggregation settings for chart vs watchlist column) the watchlist values are not consistent with "arrows" painting on the charts.
There are cases when arrows come and disappear immediately, while watchlist detecting and repeatedly reporting states. I tried adding condition to check last closed candle (see snipped below), but with no luck.

##########################################
# Momentum: RSI

script RSIMomentum {

input price = close;
input length = 14;
input over_bought = 60;
input over_sold = 40;
input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

def buySignal = rsi crosses above over_sold;
def sellSignal = rsi crosses below over_bought;

def lastClose = if !IsNaN(close) and IsNaN(close[-1]) then close else lastClose[1];

plot RSISignal = if (lastClose) then
(
if buySignal then 1 #Buy
else if sellSignal then -1 #Sell
else 0 #Neutral
) else Double.NaN;

#################END CODE
}

def _RSISignal = RSIMomentum().RSISignal;

AddLabel(yes, _RSISignal, COLOR.WHITE);

Thanks in advance
when you see a study using [-1] it is using future bar in its calculations.

Problem: "in this moment", it is not possible to know what the future might hold.
It has to be repainted.

Scripts that repaint should NOT be used in Backtesting Strategies, Conditional Orders or Scans, Watchlists, Alerts.
a. The script will fire on a false signal. The signal will then disappear. You will think the script is broken.
b. The script didn't fire on the signal. That is because it wasn't there at that time! It was painted on afterward. You will think the script is broken.

On top of which, as you have seen, it is not possible to sync up repainters between charts and watchlists.
 
Last edited:
@MerryDay could you recommend an RSI indicator based watch list column that provides signals aligned with the chart.
I am assuming that the RSI is not a repainting indicator?
 
@MerryDay could you recommend an RSI indicator based watch list column that provides signals aligned with the chart.
I am assuming that the RSI is not a repainting indicator?
Below, see the ToS RSI indicator applied to the 15min chart.

The RSI is 'technically' not a repainting indicator.
BUT obviously, there is no way to know whether the CLOSE of the current candle is going to actually close above or below your levels. So yes, the current candle updates every tick until the candle is closed.
This is true of stock indicators across all platforms.

You have a choice,
  • incur the updates until the candle closes
  • incur the lag associated with signals from the bar prior to the current candle.

shared chart setup: http://tos.mx/lTFXfcP Click here for --> Easiest way to load shared links
uCmNO5o.png


shared watchlist column script: http://tos.mx/mo1fuUh
gJ3l2OR.png

Ruby:
input price = close;
input length = 14;
input over_bought = 60;
input over_sold = 40;
input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

def buySignal = rsi crosses above over_sold;
def sellSignal = rsi crosses below over_bought;

plot wRSI = round(rsi,2);
wRSI.AssignValueColor(Color.white) ;

AssignBackgroundColor(
if buysignal then color.dark_green else
if sellsignal then color.dark_red else  color.black);

Just as we discussed [-1] references: future bars.
The syntax to reference prior bars is: [1] or [2] or [3]
You will also see it written on in long form 1 bar ago , 2 bars ago...

So this references current candle:
AssignBackgroundColor(
if buysignal then color.dark_green else
if sellsignal then color.dark_red else color.black);

This references the prior candle:
AssignBackgroundColor(
if buysignal[1] then color.dark_green else
if sellsignal[1] then color.dark_red else color.black);
 
Last edited:
Adding Color to Plots and Labels
A frequent request is for coloring plots, labels, watch lists: green for upticks, red for down.
This example can be applied to a plot of any type of oscillator.
View attachment 11868
Ruby:
# TOS RSI
declare lower ;
input show_label = yes ;
input price = close ;
input OB = 75 ;
input OS = 35 ;
input rsi_length = 14 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
# ########################################################

Plot RSI = reference RSI("price" = PRICE, "length" = rsi_length);
# ########################################################
#RSI> RSI[1] this statement is saying if the current candle is greater than the previous candle
#that is what [1] denotes. Thus defining uptick. The same is then done for downticks.
RSI.AssignValueColor(
if RSI> OB then GlobalColor("maxxed") else
if RSI< OS then GlobalColor("pretrend") else
if RSI> RSI[1] then GlobalColor("rising")
     else GlobalColor("bear"));
RSI.SetLineWeight(3);
# ########################################################

plot OverBought = OB;
plot OverSold = OS;
plot UpArrow = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownArrow = if RSI crosses below OverBought then OverBought else Double.NaN;

DefineGlobalColor("OBcolor", CreateColor(171, 171, 225)) ;
DefineGlobalColor("OScolor", CreateColor(220, 220, 128)) ;
OverBought.SetDefaultColor(GlobalColor("OBcolor"));
OverSold.SetDefaultColor(GlobalColor("OScolor"));
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
AddLabel(show_label,
         if RSI> OB then "RSI maxxed" else
         if RSI< OS then "RSI pre-trend" else
         if RSI> RSI[1] then "RSI Trending " +round(RSI,2)
              else "RSI Bear " +round(RSI,2) ,
         if RSI> OB then GlobalColor("maxxed") else
         if RSI< OS and RSI>RSI[1] then GlobalColor("pretrend") else
         if RSI> RSI[1] then GlobalColor("rising")
              else GlobalColor("bear"));
AddCloud(if RSI >= OB then RSI else Double.NaN, OB,
GlobalColor("maxxed"), GlobalColor("maxxed"));
AddCloud(if RSI <= OS then OS else Double.NaN, RSI,
GlobalColor("pretrend"), GlobalColor("pretrend"));
# ########################################################
Is there a way we could not have this as a lower study and just have the label on upper chart?
 
Is there a way we could not have this as a lower study and just have the label on upper chart?
Here ya go:
RSI upper chart label only
Ruby:
# TOS RSI upper chart label only
input price = close ;
input OB = 75 ;
input OS = 35 ;
input rsi_length = 14 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
# ########################################################

def RSI = reference RSI("price" = PRICE, "length" = rsi_length);
AddLabel(yes,
         if RSI> OB then "RSI maxxed" else
         if RSI< OS then "RSI pre-trend" else
         if RSI> RSI[1] then "RSI Trending " +round(RSI,2)
              else "RSI Bear " +round(RSI,2) ,
         if RSI> OB then GlobalColor("maxxed") else
         if RSI< OS and RSI>RSI[1] then GlobalColor("pretrend") else
         if RSI> RSI[1] then GlobalColor("rising")
              else GlobalColor("bear"));
# ########################################################
 
Here ya go:
RSI upper chart label only
Ruby:
# TOS RSI upper chart label only
input price = close ;
input OB = 75 ;
input OS = 35 ;
input rsi_length = 14 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
# ########################################################

def RSI = reference RSI("price" = PRICE, "length" = rsi_length);
AddLabel(yes,
         if RSI> OB then "RSI maxxed" else
         if RSI< OS then "RSI pre-trend" else
         if RSI> RSI[1] then "RSI Trending " +round(RSI,2)
              else "RSI Bear " +round(RSI,2) ,
         if RSI> OB then GlobalColor("maxxed") else
         if RSI< OS and RSI>RSI[1] then GlobalColor("pretrend") else
         if RSI> RSI[1] then GlobalColor("rising")
              else GlobalColor("bear"));
# ########################################################
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
450 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