I've been trying to get plots of RSI support/resistance on upper chart similar to this Tradingview study https://www.tradingview.com/script/pnc5rcY3-RSI-Support-Resistance-by-DGT/. If I declare upper; nothing plots. If I drag the study up to price chart it plots but not at correct areas. I had one other version that seemed to plot but was distorting based on zoom levels of current chart. Can anyone help or steer me in correct direction? Much appreciated. Code and picture below:
declare lower;
input length = 14;
input over_Bought = 70;
input highband = 75;
input over_Sold = 30;
input lowband = 25;
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);
# ---------------------------------- Add Cloud_OBOS -----------------
input Cloud_OBOS = yes;
DefineGlobalColor( "OBCloud", color.red);
DefineGlobalColor( "OSCloud", color.green);
def OB1 = over_Bought;
def OB2 = highband;
def OS1 = over_Sold;
def OS2 = lowband;
DefineGlobalColor("Overbought", Color.light_GRAY);
AddCloud(if Cloud_OBOS then OB1 else Double.NaN, OB2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
DefineGlobalColor("Oversold", Color.light_GRAY);
AddCloud(if Cloud_OBOS then OS1 else Double.NaN, OS2, GlobalColor("OSCloud"), GlobalColor("OSCloud"));
declare lower;
input length = 14;
input over_Bought = 70;
input highband = 75;
input over_Sold = 30;
input lowband = 25;
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);
# ---------------------------------- Add Cloud_OBOS -----------------
input Cloud_OBOS = yes;
DefineGlobalColor( "OBCloud", color.red);
DefineGlobalColor( "OSCloud", color.green);
def OB1 = over_Bought;
def OB2 = highband;
def OS1 = over_Sold;
def OS2 = lowband;
DefineGlobalColor("Overbought", Color.light_GRAY);
AddCloud(if Cloud_OBOS then OB1 else Double.NaN, OB2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
DefineGlobalColor("Oversold", Color.light_GRAY);
AddCloud(if Cloud_OBOS then OS1 else Double.NaN, OS2, GlobalColor("OSCloud"), GlobalColor("OSCloud"));