RSI Format, Label, Watchlist, Scan For ThinkOrSwim

Can someone kindly help me correct my errors, please

Code:
def rsi1 = RSIWilder("15 min" = 95, price = close(period = AggregationPeriod.fifteen));
AddLabel(yes, rsi1, if rsi1 >= 95 then Color.green else if rsi1 < 94 and rsi1 > 30 then Color.yellow else color.red );

def rsi2 = RSIWilder("5 min" = 95, price = close(period = AggregationPeriod.five));
AddLabel(yes, rsi2, if rsi2 >= 95 then Color.green else if rsi2 < 94 and rsi2 > 30 then Color.yellow else color.red );

def rsi3 = RSIWilder("1 min" = 95, price = close(period = AggregationPeriod.one));
AddLabel(yes, rsi3, if rsi3 >= 95 then Color.green else if rsi3 < 94 and rsi3 > 30 then Color.yellow else color.red );
 
lee, here is some code to compare with your original. Please note, there is not a rsiwilder() function, but a rsi() function, that has wilder average as default. I was not sure whether you wanted a length of '95' (eg: "15 min" = 95) instead of the default of '14', so I made it a variable input that you can modify as needed. Hope this helps.
Code:
input length = 95;
def rsi1 = rsi(length = length, price = close(period = AggregationPeriod.FIFTEEN_MIN));
AddLabel(yes, "15 min = " + round(rsi1), if rsi1 >= 95 then Color.green else if rsi1 < 94 and rsi1 > 30 then Color.yellow else color.red );

def rsi2 = RSI(length = length, price = close(period = AggregationPeriod.FIVE_MIN));
AddLabel(yes, "5 min = " + round(rsi2), if rsi2 >= 95 then Color.green else if rsi2 < 94 and rsi2 > 30 then Color.yellow else color.red );

def rsi3 = RSI(length= length, price = close(period = AggregationPeriod.MIN));
AddLabel(yes, "1 min = " + round(rsi3), if rsi3 >= 95 then Color.green else if rsi3 < 94 and rsi3 > 30 then Color.yellow else color.red );
 
I am using the TOS RSI indicator but it has 30 and 70 lines drawn. I want to add 50 line with a different color.? Any advise how to modify the below code.

Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

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);
 
Hi I was wondering if the community ca help me put to get buy signal arrows on my chart based on overbought and oversold levels. This is what I have so far but doesnt work. Thanks in advance.

def buy = RSI().upsignal;
def sell = RSI().downSignal;

US.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DS.SetDefaultColor(Color.DOWNTICK);
 
Basic Elements For A Plot

@DivNDrip Your logic is fine. The syntax for plotting on a chart requires some basic elements as described below. The good news is that the syntax will work in all studies so I keep a sample file similar to the below script that I can plug and play into any study that I want. This way, I never forget one of the parts.
  1. The item you are attempting to plot must start w/ a plot statement. def statements define but don't actually plot anything
  2. The plot statement must say where you want the item to plot on your chart, simple choices are on the high part of the candle or on the low part of the candle.
  3. The Set formatting statements must be preceded by the name of each of the variables in the plot statements.
Ruby:
plot buy = if RSI().upsignal then low else double.NaN;
plot sell = if RSI().downSignal then high else double.NaN;

buy.SetPaintingStrategy(PaintingStrategy.ARROW_up);
buy.SetLineWeight(1);
buy.SetDefaultColor(color.uptick) ;

sell.SetPaintingStrategy(PaintingStrategy.ARROW_down);
sell.SetLineWeight(1);
sell.SetDefaultColor(color.downtick) ;
zXmTnjZ.png

HTH
 
Last edited:
Hi -

This is my first time posting but have been reading through the forum for awhile now. Great information here.
I'm trying to create a RSI scan, where the RSI line turns red before it reaches the 70 line (OverBought). For example the RSI turns red but the value is at 61, or any value below the 70 line. I would like to use the 5-10 min time frame. Can there be an alert exactly when the RSI turns red even before the close of the candle?
See image below.
hcZhA3L.png


Thank you for any insight anyone might have.
 
I don't have a scan for it yet - still trying to figure that out. Not sure how to scan for the RSI turning red?

@rhmillion You can't scan for a "color" in Thinkorswim using Thinkscript, you can only scan for the "condition" that triggers the color to be painted a color... What causes the color to be red on "your" chart...??? That's what you scan for... But remember, everyone's chart doesn't paint the same colors... That's why we use "conditions", or "criteria"... And the default color is "orange", not "red"... But I digress...

What makes the color turn color is being overbought... And the default "condition" is rsi crosses 70 or rsi crosses overBought... There should be a plot for the breakout that you can scan for... In your Conditon Wizard it would end up being close crosses above RSI()."OverBought" if you are using the default RSI...

That should be enough breadcrumbs for you to figure things out...
 
@mdtn @rhmillion take a look at my post and script below. Since you have a watchlist already, then you can just add a column into the watchlist that will tell you oversold or overbought in the last bars. I posted the script and screenshot below. The script is set for 80/20, you can just modify that to 70/30 on a 1-minute aggregation. I've tried and tested to add an alert inside the script in watchlist, it will not fire and not allowed (asked support already).

Good luck! @cabe1332

https://usethinkscript.com/threads/...icators-for-thinkorswim.182/page-3#post-61575
 
Last edited:
Hello,

Looking for help on creating code on my current watchlist if RSI is crossed above 80 or below 20. If its above 80 make it Green color, red for below 20, and gray for neutral (in between)

Appreciate the help

And thanks everyone for all the amazing stuff you've done on this forum
 
Could you point me at some so I can take a stab at it and see what can be done,

Thanks appreciate it
This should do the trick. Definitely look at how the code is put together. Its fairly easy to replicate this type of stuff on other indicators you may use. Hope this helps!

Code:
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
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);


def OB = RSI >= Over_Bought;
def OS = RSI <= Over_Sold;

AssignBackgroundColor(if OB then color.light_red else if OS then color.dark_green else color.black);
 
Last edited:
This should do the trick. Definitely look at how the code is put together. Its fairly easy to replicate this type of stuff on other indicators you may use. The "meat" of the code starts with the line that says plot RSI. One plot is expected (what you plot will determine the # you see on your watchlist). Then define the OB/OS and assign the background color for your OB/OS conditions. The front part of the code is already in TOS, so just copy and paste pretty much. Hope this helps!

Code:
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);


def OB = RSI >= Over_Bought;
def OS = RSI <= Over_Sold;

AssignBackgroundColor(if OB then color.light_red else if OS then color.dark_green else color.black);
 
Thanks @Christopher84

Can you explain to me what these lines mean:

def NetChgAvg = MovingAverage(averageType, price - price[1], length);

I'm confused on the -> MovingAverage ( the brackets inside i understand )

same with the:

def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);

AbsValue? I am speculating it has something to do with where the RSI currently is or?


plot RSI = 50 * (ChgRatio + 1);

Why are we times 50 here, where does that number come from?

Thanks for taking your time, just trying to understand things better :)
 
Thanks @Christopher84

Can you explain to me what these lines mean:

def NetChgAvg = MovingAverage(averageType, price - price[1], length);

I'm confused on the -> MovingAverage ( the brackets inside i understand )

same with the:

def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);

AbsValue? I am speculating it has something to do with where the RSI currently is or?


plot RSI = 50 * (ChgRatio + 1);

Why are we times 50 here, where does that number come from?

Thanks for taking your time, just trying to understand things better :)
plot RSI = 50 * (ChgRatio + 1); Is just the formula to determine RSI. Inside the brackets are the various components used in its calculation (averageType(the type of average specified in the inputs), price (current price) - price[1](price one period back), length (the period of time specified in your inputs)). AbsValue stands for absolute value. So in practice "absolute value" means to remove any negative sign in front of a number, and to think of all numbers as positive (or zero). In other words the absolute value of 6 and -6 is the exact same, 6. Absolute value comes in handy when you are trying to measure change and don't want negative values. If you right click on RSI under studies and select view, you will see the code/formula for RSI (which is the same as what I posted above).
 
Could someone assist me in editing this script for the RSI so it shows the value in the label and is color coded:

above 70 being red
below 30 being green

AddLabel(yes, "RSI", if rsi > rsi[1] then Color.GREEN else if rsi < rsi[1] then Color.RED else Color.GRAY);

Right now all i'm seeing is the label with the RSI in color however there is no numerical value their.
 
Last edited:

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