Count RSI oversold for previous 100 bars


Category:
0
0

Hi Pete,

Please help me with a customize column showing the number of RSI bars above 60 over the previous 100.

Thank you!

Marked as spam
Posted by (Questions: 20, Answers: 27)
Asked on March 22, 2021 3:09 pm
158 views
0
Private answer

In this solution I have included a user input to adjust the number of bars to include in the count. At the bottom of the code I included counts for both the overbought as well as the oversold. Only one of these can be plotted at one time in the watchlist column. You can adjust which one is displayed using the last line in the code.

declare lower;
input spanOfBars = 100;
input rsiLength = 14;
input rsiPrice = close;
input rsiAverageType = AverageType.WILDERS;
input overbought = 60;
input oversold = 40;
def netChangeAverage = MovingAverage(rsiAverageType, rsiPrice - rsiPrice[1], rsiLength);
def totalChangeAverage = MovingAverage(rsiAverageType, AbsValue(rsiPrice - rsiPrice[1]), rsiLength);
def changeRatio = if totalChangeAverage != 0 then netChangeAverage / totalChangeAverage else 0;
def rsi = 50 * (changeRatio + 1);
def countOversold = Sum(rsi > overbought, spanOfBars);
def countOverbought = Sum(rsi < oversold, spanOfBars);
plot data = countOversold;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 22, 2021 5:16 pm
0
Thank you so much Pete! This is exactly what I'm looking for!
( at March 22, 2021 11:12 pm)
0
Hi Pete, How would you tweak this to have the results show percentage instead of value? Thanks again!
( at March 30, 2021 12:17 pm)
0
Replace the final line of code with this? plot data = countOversold / spanOfBars;
( at March 30, 2021 12:51 pm)