RSI HistoAlert Strategy for ThinkorSwim

rad14733

Well-known member
VIP
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 = 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);

# Alert Code
input useAlerts = yes;
Alert(useAlerts and rsiHist crosses above zeroline, "RSI_HistoAlert xUp", Alert.BAR, Sound.Chimes);
Alert(useAlerts and rsiHist crosses below zeroline, "RSI_HistoAlert xDown", Alert.BAR, Sound.Chimes);

# END - RSI_HistoAlert_Strategy
 
Last edited:

jdstrader

New member
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!
 

rad14733

Well-known member
VIP
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:

wheelman

New member
Hey everyone,

There's this RSI Histo indicator on TradingView (https://www.tradingview.com/script/bXMVCkJK-RSI-HistoAlert-Strategy/) that I use a lot to detect a trend change and I was wondering if anyone has it or could potentially create it for TOS. The code seems simple enough but I wouldn't know where to begin 😅

Thanks a lot!
Hi, jdstrader.

Never have posted here. Thought I'd help out with a version I wrote based on the TradingView HistoAlert since I use ToS.

Hope this helps.

#
# Project Wanderlust
# Modified HistoAlert. Credit given to Tradingview.
#
declare lower;
#
input length = 13;
input OverBought = 70;
input OverSold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = yes;
input HistoModifyConstant = 1.5;
input HistoModifyDelta = 50;
input BuyAlert = -10;
input SellAlert = 10;
input datum = 0;
#
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 HistoAlert = (RSI-HistoModifyDelta)*HistoModifyConstant;
HistoAlert.SetLineWeight(1);
plot DatumCenter = datum;
plot UpSignal = if RSI crosses below OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses above OverBought then OverBought else Double.NaN;
#
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
#
Alert (UpSignal, "Bullish move.", Alert.BAR, Sound.Bell);
Alert (DownSignal, "Bearish move.", Alert.BAR, Sound.Bell);
#
#******************************
# Formatting stuff.
HistoAlert.AssignValueColor(if HistoAlert > 0 then color.green else if HistoAlert < 0 then color.red else color.gray);
DatumCenter.SetDefaultColor(CreateColor(204, 204, 102));
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > OverBought then RSI.color("OverBought") else if RSI < OverSold then RSI.color("OverSold") else RSI.color("Normal"));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
AddCloud(HistoAlert,DatumCenter,Color.Light_GREEN,Color.Light_RED,no);
#
RSI.HideBubble();
DatumCenter.HideBubble();
HistoAlert.HideBubble();
UpSignal.HideBubble();
DownSignal.HideBubble();
#
RSI.HideTitle();
DatumCenter.HideTitle();
HistoAlert.HideTitle();
UpSignal.HideTitle();
DownSignal.HideTitle();
#
# Formatting stuff.
#******************************
# end
 

Similar threads

Top