The following code is a TOS stock code for RSI. By default, an arrow is plotted when the rsi < over_bought and also when the rsi > over_sold. What I have been racking my brain to figure out how to plot an arrow, or point(doesnt matter) when rsi = rsi. In other word, when it is neither overbought nor oversold. In other words, the text that is bolded below. I've tried everything. Is there anyone that can help me with this?
programming is about using formulas to evaluate numbers.
if you want something different to happen, try to think of which variables and/or numbers to compare to to make it happen.
if you want to do something when rsi is neither overbought nor oversold, then rsi has a value between them.
for reference, the default values,
input over_Bought = 70;
input over_Sold = 30;
the easiest thing would be to set this built in setting to yes.
input showBreakoutSignals = no
then you will have an arrow on the first bar that rsi enters the 'normal' price range.
you could have created a formula to determine when rsi is in your desired range.
then use that variable to trigger something to happen on the chart.
def normal = if rsi < over_Bought and rsi > over_Sold then 1 else 0;
like moxiesmiley did, but use def instead of plot.
there is no reason to plot a boolean value on a chart with other values. the values, 0 or 1, are so small compared to the other values on the chart, that the changes can barely be seen. and it shifts the main plot, reducing its size.
instead of plotting the variable normal, use it to enable a row of points or some shading between 30 and 70, like in this version.
Ruby:
# rsi_normal_zone
# RSI
# TD Ameritrade IP Company, Inc. (c) 2007-2022
declare lower;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
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;
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#-------------------------------------------
# copy original RSI and add this
def na = double.nan;
# add points at 50 , for normal zone
def normal = if rsi < over_Bought and rsi > over_Sold then 1 else 0;
input show_points_when_normal = yes;
plot p = if normal then 50 else na;
p.SetPaintingStrategy(PaintingStrategy.POINTS);
p.SetDefaultColor(Color.cyan);
p.setlineweight(2);
p.hidebubble();
# add shading when rsi is in normal zone
input show_shading_when_normal = yes;
def cloudtop = if normal then over_Bought else na;
def cloudbot = if normal then over_sold else na;
addcloud(cloudtop, cloudbot, color.gray, color.gray);
#
this shows both of these set to yes
input show_points_when_normal = yes;
input show_shading_when_normal = yes;