RSI_Stochastic

woulf1004

Active member
Hi,

I have tried to integrate the RSI indicator to plot only the Up and Down Signals on the Stochastic indicator provided by TOS but no luck.
Can someone take a look and possible make it work? Thanks in advance.


Simply have both up and dow signals generated from the RSI indicator to plot on the Stochastic indicator. Could you make the BreakoutSignals from the RSI to work on the Stochastic indicator? No other plots from the RSI is needed.

input length = 20;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input barcolor = yes;

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 + if IsNaN(close) then Double.NaN else 0;
plot OverBought = over_Bought + if IsNaN(close) then Double.NaN else 0;

plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;


Any updates for this request will be highly appreciated. Thanks.
 

Attachments

  • Screenshot 2024-05-15 at 10.05.07 PM.png
    Screenshot 2024-05-15 at 10.05.07 PM.png
    169.1 KB · Views: 186
Last edited by a moderator:
Solution
Hi,

I have tried to integrate the RSI indicator to plot only the Up and Down Signals on the Stochastic indicator provided by TOS but no luck.
Can someone take a look and possible make it work? Thanks in advance.

declare lower;

input length = 20;
input over_Bought_RSI = 70;
input over_Sold_RSI = 30;
input bullish_dash_rsi = 80;
input bearish_dash_rsi = 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;

def RSI = 50 * (ChgRatio + 1);
def OverSold_RSI = over_Sold_RSI +...
Hi,

I have tried to integrate the RSI indicator to plot only the Up and Down Signals on the Stochastic indicator provided by TOS but no luck.
Can someone take a look and possible make it work? Thanks in advance.

declare lower;

input length = 20;
input over_Bought_RSI = 70;
input over_Sold_RSI = 30;
input bullish_dash_rsi = 80;
input bearish_dash_rsi = 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;

def RSI = 50 * (ChgRatio + 1);
def OverSold_RSI = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
def OverBought_RSI = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;
def bullish_zone = bullish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
def bearish_zone = bearish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
def MidLine = 50 + if IsNaN(close) then Double.NaN else 0;
def OverSold = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
def OverBought = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;

######################################################

input over_bought = 50.0;
input over_sold = -50.0;
input over_bought_dash = 40.0;
input over_sold_dash = -40.0;
input percentDLength = 5;
input percentKLength = 50;
input colorNormLength = 12;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
#smi.setDefaultColor(getColor(1));
SMI.DefineColor("High", Color.CYAN);
SMI.DefineColor("Low", Color.MAGENTA);
SMI.AssignNormGradientColor(colorNormLength, SMI.Color("Low"), SMI.Color("High"));

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));

plot overbought_S = over_bought + if IsNaN(close) then Double.NaN else 0;
overbought_S.SetDefaultColor(GetColor(5));

plot overbought_dash = over_bought_dash + if IsNaN(close) then Double.NaN else 0;
overbought_S.SetDefaultColor(GetColor(5));

plot oversold_S = over_sold + if IsNaN(close) then Double.NaN else 0;
oversold_S.SetDefaultColor(GetColor(5));

plot oversold_dash = over_sold_dash + if IsNaN(close) then Double.NaN else 0;
oversold_S.SetDefaultColor(GetColor(5));

plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN + SMI;

plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN + SMI;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Any updates on this will be highly appreciated. Thanks.

Can someone help fixing this script please?

there were quite a few wrong 'if then' code lines
i commented them out and added new lines
adding a number to double.nan will be a double.nan value.
don't need to create new rsi overbought/oversold variables. just use the input variables.
i almost missed this. it was the last piece to turn on the arrows.
input show_rsi_BreakoutSignals = yes;


Code:
#stoch_with_rsi_signals

#https://usethinkscript.com/threads/advanced_stochastic.18749/
# plot RSI Up and Down Signals on the Stochastic 

declare lower;

def na = Double.NaN;
def bn = BarNumber();

#-------------------------------
# RSI
input RSI_length = 20;
input over_Bought_RSI = 70;
input over_Sold_RSI = 30;
input bullish_dash_rsi = 80;
input bearish_dash_rsi = 20;
input price = close;
input averageType = AverageType.WILDERS;
input show_rsi_BreakoutSignals = yes;

def NetChgAvg = MovingAverage(averageType, price - price[1], rsi_length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), rsi_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
#def OverSold_RSI = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
#def OverBought_RSI = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;
#def bullish_zone = bullish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
#def bearish_zone = bearish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
def MidLine = 50 + if IsNaN(close) then Double.NaN else 0;

#def OverSold = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
#def OverBought = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;

input show_rsi_lines = no;
plot zrsi = if show_rsi_lines then rsi else na;
plot zrsiob = if show_rsi_lines then over_Bought_RSI else na;
plot zrsios = if show_rsi_lines then over_Sold_RSI else na;
zrsi.SetDefaultColor(Color.yellow);
zrsiob.SetDefaultColor(Color.yellow);
zrsios.SetDefaultColor(Color.yellow);



#-------------------------------

#  StochasticMomentumIndex
input over_bought = 50.0;
input over_sold = -50.0;
input over_bought_dash = 40.0;
input over_sold_dash = -40.0;
input percentDLength = 5;
input percentKLength = 50;
input colorNormLength = 12;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
#smi.setDefaultColor(getColor(1));
SMI.DefineColor("High", Color.CYAN);
SMI.DefineColor("Low", Color.MAGENTA);
SMI.AssignNormGradientColor(colorNormLength, SMI.Color("Low"), SMI.Color("High"));

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));

#plot overbought_S = over_bought + if IsNaN(close) then Double.NaN else 0;
plot overbought_S = if IsNaN(close) then na else over_bought;
overbought_S.SetDefaultColor(GetColor(5));

#plot overbought_dash = over_bought_dash + if IsNaN(close) then Double.NaN else 0;
plot overbought_dash = if IsNaN(close) then na else over_bought_dash;
overbought_S.SetDefaultColor(GetColor(5));

#plot oversold_S = over_sold + if IsNaN(close) then Double.NaN else 0;
plot oversold_S = if IsNaN(close) then na else over_sold;
oversold_S.SetDefaultColor(GetColor(5));

#plot oversold_dash = over_sold_dash + if IsNaN(close) then Double.NaN else 0;
plot oversold_dash = if IsNaN(close) then na else over_sold_dash;
oversold_dash.SetDefaultColor(GetColor(5));

#----------------------------

# RSI plots
#plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN + SMI;
#plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN + SMI;
plot UpSignal = if RSI crosses above over_Sold_RSI then smi else na;
plot DownSignal = if RSI crosses below over_Bought_RSI then smi else na;

UpSignal.SetHiding(!show_rsi_BreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetHiding(!show_rsi_BreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#-------------------------------
#
 

Attachments

  • img1.JPG
    img1.JPG
    60 KB · Views: 139
Solution
there were quite a few wrong 'if then' code lines
i commented them out and added new lines
adding a number to double.nan will be a double.nan value.
don't need to create new rsi overbought/oversold variables. just use the input variables.
i almost missed this. it was the last piece to turn on the arrows.
input show_rsi_BreakoutSignals = yes;


Code:
#stoch_with_rsi_signals

#https://usethinkscript.com/threads/advanced_stochastic.18749/
# plot RSI Up and Down Signals on the Stochastic

declare lower;

def na = Double.NaN;
def bn = BarNumber();

#-------------------------------
# RSI
input RSI_length = 20;
input over_Bought_RSI = 70;
input over_Sold_RSI = 30;
input bullish_dash_rsi = 80;
input bearish_dash_rsi = 20;
input price = close;
input averageType = AverageType.WILDERS;
input show_rsi_BreakoutSignals = yes;

def NetChgAvg = MovingAverage(averageType, price - price[1], rsi_length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), rsi_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
#def OverSold_RSI = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
#def OverBought_RSI = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;
#def bullish_zone = bullish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
#def bearish_zone = bearish_dash_rsi + if IsNaN(close) then Double.NaN else 0;
def MidLine = 50 + if IsNaN(close) then Double.NaN else 0;

#def OverSold = over_Sold_RSI + if IsNaN(close) then Double.NaN else 0;
#def OverBought = over_Bought_RSI + if IsNaN(close) then Double.NaN else 0;

input show_rsi_lines = no;
plot zrsi = if show_rsi_lines then rsi else na;
plot zrsiob = if show_rsi_lines then over_Bought_RSI else na;
plot zrsios = if show_rsi_lines then over_Sold_RSI else na;
zrsi.SetDefaultColor(Color.yellow);
zrsiob.SetDefaultColor(Color.yellow);
zrsios.SetDefaultColor(Color.yellow);



#-------------------------------

#  StochasticMomentumIndex
input over_bought = 50.0;
input over_sold = -50.0;
input over_bought_dash = 40.0;
input over_sold_dash = -40.0;
input percentDLength = 5;
input percentKLength = 50;
input colorNormLength = 12;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
#smi.setDefaultColor(getColor(1));
SMI.DefineColor("High", Color.CYAN);
SMI.DefineColor("Low", Color.MAGENTA);
SMI.AssignNormGradientColor(colorNormLength, SMI.Color("Low"), SMI.Color("High"));

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));

#plot overbought_S = over_bought + if IsNaN(close) then Double.NaN else 0;
plot overbought_S = if IsNaN(close) then na else over_bought;
overbought_S.SetDefaultColor(GetColor(5));

#plot overbought_dash = over_bought_dash + if IsNaN(close) then Double.NaN else 0;
plot overbought_dash = if IsNaN(close) then na else over_bought_dash;
overbought_S.SetDefaultColor(GetColor(5));

#plot oversold_S = over_sold + if IsNaN(close) then Double.NaN else 0;
plot oversold_S = if IsNaN(close) then na else over_sold;
oversold_S.SetDefaultColor(GetColor(5));

#plot oversold_dash = over_sold_dash + if IsNaN(close) then Double.NaN else 0;
plot oversold_dash = if IsNaN(close) then na else over_sold_dash;
oversold_dash.SetDefaultColor(GetColor(5));

#----------------------------

# RSI plots
#plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN + SMI;
#plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN + SMI;
plot UpSignal = if RSI crosses above over_Sold_RSI then smi else na;
plot DownSignal = if RSI crosses below over_Bought_RSI then smi else na;

UpSignal.SetHiding(!show_rsi_BreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetHiding(!show_rsi_BreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#-------------------------------
#
I think there is something missing or not aligning properly. Attached and image for your reference so you can see breakout signals on RSI indicator not being reflected on the Stochastic indicator. Please check and advise.
 

Attachments

  • Screenshot 2024-05-17 at 9.23.19 PM.png
    Screenshot 2024-05-17 at 9.23.19 PM.png
    153.7 KB · Views: 123
So the script or concept in the below will not work when applying to a RSI indicator?

# MTF Moving Average

input Period = aggregationPeriod.HOUR;
input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

plot AVG = MovingAverage(AvgType, close(period = Period), Length);
AVG.setdefaultcolor(color.yellow);
 

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