RSI indicator two lengths

BY23

New member
I need some coding help please. I am wanting to take the original ToS RSI code and adjust the variables to add two plots in the same indicator. However the "slow length" keeps plotting differently than if I stack two RSI indicators together. I also want a line plotted at 50 and when simply adding two standard RSI codes with a plot at 50 the plot does not plot at 50 due to it changing to a percentage based scale which would be the easy solution. Here is the code I have for the two RSI (Fast & Slow) and an image of the difference. The white 2px line in Slowlength 28 length line from my script and the cyan 2px line is the RSI 28 length from the standard ToS script. I've checked this for any errors for two days over and over and can not figure out why this won't plot correctly. Any suggestion would be appreciated, thanks in advance!

Screenshot 2024-11-01 105945.png


Code:
declare lower;

input Slowlength = 28;
input SlowAverageType = AverageType.SIMPLE;

input Fastlength = 5;
input FastAverageType = AverageType.SIMPLE;

input price = close;

def NetChgAvgSlow = MovingAverage(SlowAverageType, price - price[1], Slowlength);
def TotChgAvgSlow = MovingAverage(SlowAverageType, AbsValue(price - price[1]), Slowlength);
def ChgRatioSlow = if TotChgAvgSlow != 0 then NetChgAvgSlow / TotChgAvgSlow else 0;

plot RSISlow = 50 * (ChgRatioSlow + 1);
RSISlow.SetDefaultColor(CreateColor(255, 255, 255));
RSISlow.SetLineWeight (2);

def NetChgAvgFast = MovingAverage(FastAverageType, price - price[1], Fastlength);
def TotChgAvgFast = MovingAverage(FastAverageType, AbsValue(price - price[1]), Fastlength);
def ChgRatioFast = if TotChgAvgFast != 0 then NetChgAvgFast / TotChgAvgFast else 0;

plot RSIFast = 50 * (ChgRatioFast + 1);
RSIFast.SetDefaultColor(CreateColor(125, 125, 125));

plot Line = 50;
Line.SetDefaultColor(CreateColor(255, 0, 0));
 

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