RSI HistoAlert Indicator for ThinkorSwim

While the standard TOS RSI Indicator can be displayed as a Histogram the code in the link provided is a bit different... I have converted my interpretation of the Tradingview version on top of the TOS standard RSI Indicator...

NOTE: This is NOT a standard RSI indicator...!!! It uses a zeroline instead of a 50 line, which is also not in all standard RSI indicators by default, doesn't actually use 70/30 OB/OS, and has BuyAlertLevel line @-10 and SellAlertLevel line at @10... Other than that it's a RSI Histogram/Line combo... No average line... So quite different than the standard RSI...

Releases
# v1.0 : 2021-02-23 : Initial Release
# v1.1 : 2021-02-24 : Added sound alerts for zeroline crossover



Ruby:
# RSI_HistoAlert_Strategy
# Based on code located at: https://www.tradingview.com/script/bXMVCkJK-RSI-HistoAlert-Strategy/
# Derived from TOS standard RSI Study
# Converted by rad14733 for usethinkscript.com
#hint: Paints both RSI histogram and line, plus Buy and Sell alert lines.\nNote that this version uses a different scale than the standard RSI Indicator.
# v1.0 : 2021-02-23 : Initial Release
# v1.1 : 2021-02-24 : Added sound alerts for zeroline crossover

declare lower;

input length = 13; #14
input over_Bought = 20;
input over_Sold = -20;
input showBreakoutSignals = yes;
input buyAlertValue = -10;
input sellAlertValue = 10;
input showZerolineCrossovers = yes;
input showRsiLine = no;
input showAvgRSI = yes;
input showZeroLine = no;
input showAvgRsiCloud = yes;
input showAvgRSICrossovers = yes;
input useZerolineAlerts = no;
input price = close;
input averageType = AverageType.WILDERS;

def rsi = RSI(length, over_Bought, over_Sold, price, averageType, showBreakoutSignals) - 50;

plot rsiHist = rsi;
rsiHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
rsiHist.SetLineWeight(3);
rsiHist.assignValueColor(
   if  rsiHist > 0 and rsiHist >= rsiHist[1]
   then Color.CYAN
   else if rsiHist > 0 and rsiHist < rsiHist[1]
   then Color.DARK_ORANGE
   else if rsiHist < 0 and rsiHist <= rsiHist[1]
   then Color.RED
   else Color.YELLOW
);
#rsiHist.AssignValueColor(if rsi > 0 then Color.GREEN else Color.RED); #Original

plot rsiLine = if showRsiLine then rsi else Double.NaN;
rsiLine.SetPaintingStrategy(PaintingStrategy.LINE);
rsiLine.SetDefaultColor(Color.BLUE);
rsiLine.SetLineWeight(2);

plot zeroline = if showZeroLine then 0 else Double.NaN;
zeroline.SetDefaultColor(Color.WHITE);
zeroline.SetPaintingStrategy(PaintingStrategy.LINE);
zeroline.SetStyle(Curve.FIRM);
zeroline.SetLineWeight(1);

# Zeroline Crossover Indicators

plot xUp = if showZerolineCrossovers and rsi crosses above zeroline then zeroline - 1 else Double.NaN;
xUp.SetDefaultColor(Color.DARK_GREEN);
xUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
xUp.SetLineWeight(1);

plot xDown = if showZerolineCrossovers and rsi crosses below zeroline then zeroline + 1 else Double.NaN;
xDown.SetDefaultColor(Color.DARK_RED);
xDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
xDown.SetLineWeight(1);


plot BuyAlertLevel = buyAlertValue;
BuyAlertLevel.SetDefaultColor(Color.YELLOW);
BuyAlertLevel.SetPaintingStrategy(PaintingStrategy.LINE);
BuyAlertLevel.SetStyle(Curve.SHORT_DASH);
BuyAlertLevel.SetLineWeight(1);

plot SellAlertLevel = sellAlertValue;
SellAlertLevel.SetDefaultColor(Color.YELLOW);
SellAlertLevel.SetPaintingStrategy(PaintingStrategy.LINE);
SellAlertLevel.SetStyle(Curve.SHORT_DASH);
SellAlertLevel.SetLineWeight(1);

# v1.1 : Alert Code

Alert(useZerolineAlerts and rsi crosses above zeroline, "RSI_HistoAlert xUp", Alert.BAR, Sound.Ding);
Alert(useZerolineAlerts and rsi crosses below zeroline, "RSI_HistoAlert xDown", Alert.BAR, Sound.Ding);

# v1.2 : Average RSI Line and Crossover Indicators

plot avgRSI = if showAvgRSI then Average(rsi, length) else Double.NaN;
#avgRSI.AssignValueColor(if rsi > avgRsi then Color.Green else Color.RED);
avgRSI.SetPaintingStrategy(PaintingStrategy.LINE);
avgRSI.SetStyle(Curve.FIRM);
avgRSI.SetLineWeight(2);
avgRSI.AssignValueColor(
      if rsiHist > avgRsi and rsiHist > 0
      then Color.WHITE
      else if rsiHist > 0 and rsiHist < avgRsi
      then Color.RED
      else if rsiHist < 0 and rsiHist < avgRsi
      then Color.WHITE
      else Color.CYAN
);
avgRSI.AssignValueColor(Color.WHITE);


plot xAvgUp = if showAvgRSICrossovers and (rsi crosses above avgRSI and rsi > rsi[1]) then avgRSI else Double.NaN;
xAvgUp.SetDefaultColor(Color.ORANGE);
xAvgUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
xAvgUp.SetLineWeight(1);

plot xAvgDown = if showAvgRSICrossovers and (rsi crosses below avgRSI and rsi < rsi[1]) then avgRSI else Double.NaN;
xAvgDown.SetDefaultColor(Color.YELLOW);
xAvgDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
xAvgDown.SetLineWeight(1);


# RSI Breakout OB/OS Lines and Crossovers

plot obPlot = if showBreakoutSignals then over_Bought else Double.NaN;
obPlot.SetDefaultColor(Color.WHITE);
obPlot.SetPaintingStrategy(PaintingStrategy.LINE);
obPlot.SetStyle(Curve.FIRM);
obPlot.SetLineWeight(1);

plot osPlot = if showBreakoutSignals then over_Sold else Double.NaN;
osPlot.SetDefaultColor(Color.WHITE);
osPlot.SetPaintingStrategy(PaintingStrategy.LINE);
osPlot.SetStyle(Curve.FIRM);
osPlot.SetLineWeight(1);

plot osXover = if showBreakoutSignals and (rsi crosses above over_Sold and rsi > rsi[1]) then over_Sold else Double.NaN;
osXover.SetDefaultColor(Color.GREEN);
osXover.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
osXover.SetLineWeight(1);

plot obXbelow = if showBreakoutSignals and (rsi crosses below over_Bought and rsi < rsi[1]) then over_Bought else Double.NaN;
obXbelow.SetDefaultColor(Color.RED);
obXbelow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
obXbelow.SetLineWeight(1);

# AddCloud - rad14733 - v1.1
AddCloud(if showAvgRsiCloud then 0 else Double.Nan, if showAvgRsiCloud then avgRsi else Double.Nan, Color.WHITE, Color.WHITE);

# END - RSI_HistoAlert_Strategy
 
Last edited:
While the standard TOS RSI Indicator can be displayed as a Histogram the code in the link provided is a bit different... I have converted my interpretation of the Tradingview version on top of the TOS standard RSI Indicator...

Ruby:
# RSI_HistoAlert_Strategy
# Based on code located at: https://www.tradingview.com/script/bXMVCkJK-RSI-HistoAlert-Strategy/
# Derived from TOS standard RSI Study
# Converted by rad14733 for usethinkscript.com
#hint: Paints both RSI histogram and line, plus Buy and Sell alert lines.\nNote that this version uses a different scale than the standard RSI Indicator.
# v1.0 : 2021-02-23 : Initial Release

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input buyAlertValue = -10;
input sellAlertValue = 10;

def rsi = RSI(length, over_bought, over_sold, price, averageType, showBreakoutSignals) - 50;

plot rsiLine = rsi;
rsiLine.SetPaintingStrategy(PaintingStrategy.LINE);
rsiLine.SetDefaultColor(Color.BLUE);
rsiLine.SetLineWeight(3);

plot rsiHist = rsi;
rsiHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
rsiHist.AssignValueColor(if rsi > 0 then Color.GREEN else Color.RED);
rsiHist.SetLineWeight(1);

plot zeroline = 0;
zeroline.SetDefaultColor(Color.WHITE);

plot BuyAlertLevel = buyAlertValue;
BuyAlertLevel.SetDefaultColor(Color.YELLOW);
BuyAlertLevel.SetPaintingStrategy(PaintingStrategy.LINE);
BuyAlertLevel.SetStyle(Curve.SHORT_DASH);
BuyAlertLevel.SetLineWeight(1);

plot SellAlertLevel = sellAlertValue;
SellAlertLevel.SetDefaultColor(Color.YELLOW);
SellAlertLevel.SetPaintingStrategy(PaintingStrategy.LINE);
SellAlertLevel.SetStyle(Curve.SHORT_DASH);
SellAlertLevel.SetLineWeight(1);

# END - RSI_HistoAlert_Strategy
This is perfect. Thank you so much! Do you think you could also add a sound alert when it crosses the zero line? Thanks again!
 
This is perfect. Thank you so much! Do you think you could also add a sound alert when it crosses the zero line? Thanks again!

The code in Post #2 has been updated to include sound alerts...

Edited to add: Play with the code for a while and see whether or not BuyAlertLevel and SellAlertLevel crossover alerts would be worthwhile... I haven't had enough chance to monitor the working code to make such a determination... But I am hearing crossover alerts...
 
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
546 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