Upper Level RSI support/resistance

GoLo

Member
VIP
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"));
 

Attachments

  • RSI Support Resistance.PNG
    RSI Support Resistance.PNG
    115.3 KB · Views: 151
Solution
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 =...
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"));


you can't just put a lower study on an upper chart and expect it to conform to the range of price bars. it is hard coded to plot numbers that are between 0 and 100.

this part that was added at the end, is setting numbers for cloud levels.
def OB1 = over_Bought;
def OB2 = highband;
def OS1 = over_Sold;
def OS2 = lowband;

you would have to compare the rsi to these levels. if it crosses one of them, then assign a price level to be plotted or used in a cloud.

here is an upper , that is somewhat converted from the pine code.


Code:
#upper_rsi_levels

#https://usethinkscript.com/threads/help-upper-level-rsi-support-resistance.18141/
#Help Upper Level RSI support/resistance
#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/. 

#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;

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
def 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 -----------------


script f_getPrice {
#(_osc, _thresh, _cross) =>
 input _osc = 0;
 input _thresh = 0;
 #  down = 1 , both = 2 , up = 3 
 input _cross = 0;
 def avgHigh = (high + close)/2;
 def avgLow  = (low + close)/2;
 def return_1 = if (_cross == 3 or _cross == 2) and (_osc crosses above _thresh) then avgHigh
   else if (_cross == 1 or _cross == 2) and (_osc crosses below _thresh) then avgLow
   else return_1[1];
 plot z = return_1;
}


#f_getPrice(_osc, _thresh, _cross) =>
#    avgHigh = math.avg(high, close)
#    avgLow  = math.avg(low , close)
#    var return_1 = 0.
#    if _cross == 'over' or _cross == 'both'
#        if ta.crossover(_osc, _thresh)
#            return_1 := avgHigh
#            return_1
#    if _cross == 'under' or _cross == 'both'
#        if ta.crossunder(_osc, _thresh)
#            return_1 := avgLow
#            return_1
#    return_1



# 'Overbought', minval=50, maxval=100
input i_obThreshold = 70;
#hint i_obThreshold: 'Overbought', minval=50, maxval=100
# 'Bull Zone' , minval=50, maxval=65 
input i_bullZone    = 60;
# 'Bear Zone' , minval=35, maxval=50 
input i_bearZone    = 40;
# ' Oversold' , minval=1 , maxval=50
input i_osThreshold = 30;


def i_obThreshold2 = if i_obThreshold < 50 then 50
  else if i_obThreshold > 100 then 100
  else i_obThreshold;
def i_bullZone2 = if i_bullZone < 50 then 50
  else if i_bullZone > 65 then 65
  else i_bullZone;
def i_bearZone2 = if i_bearZone < 35 then 35
  else if  i_bearZone > 50 then 50
  else i_bearZone;
def  i_osThreshold2 = if  i_osThreshold < 1 then 1
  else if  i_osThreshold > 50 then 50
  else  i_osThreshold;


#// -Calculations ════════════════════════════════════════════════════════════════════════════════ //
#oscillator = ta.rsi(i_source == 'Price (close)' ? close : ta.obv, i_length)
#  down = 1 , both = 2 , up = 3 

def oscillator = rsi;
def crossover_overbought  = f_getPrice(oscillator, i_obThreshold2, 3);
def crossunder_overbought = f_getPrice(oscillator, i_obThreshold2, 1);
def bullZone              = f_getPrice(oscillator, i_bullZone2   , 2);
def bearZone              = f_getPrice(oscillator, i_bearZone2   , 2);
def crossover_oversold    = f_getPrice(oscillator, i_osThreshold2, 3);
def crossunder_oversold   = f_getPrice(oscillator, i_osThreshold2, 1);


addchartbubble(0, low,
 crossover_overbought + "\n" +
 crossunder_overbought + "\n" +
 bullZone + "\n" +
 bearZone + "\n" +
 crossover_oversold + "\n" +
 crossunder_oversold + "\n" 
, color.yellow, no);


plot z1 = crossover_overbought;
plot z2 = crossunder_overbought;
plot z3 = bullZone;
plot z4 = bearZone;
plot z5 = crossover_oversold;
plot z6 = crossunder_oversold;
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.red);
z2.SetDefaultColor(Color.red);
z3.SetDefaultColor(Color.yellow);
z4.SetDefaultColor(Color.yellow);
z5.SetDefaultColor(Color.green);
z6.SetDefaultColor(Color.green);


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

DefineGlobalColor( "OBCloud", color.red);
DefineGlobalColor( "OSCloud", color.green);
DefineGlobalColor("Overbought", Color.light_GRAY);
DefineGlobalColor("Oversold", Color.light_GRAY);

#def OB1 = over_Bought;
#def OB2 = highband;
#def OS1 = over_Sold;
#def OS2 = lowband;
# over_Bought = 70;
# highband = 75;
# over_Sold = 30;
# lowband = 25;

input Cloud_OBOS = yes;
#AddCloud(if Cloud_OBOS then OB1 else Double.NaN, OB2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
#addCloud(if Cloud_OBOS then OS1 else Double.NaN, OS2, GlobalColor("OSCloud"), GlobalColor("OSCloud"));

# if enabled, kill the lines ?
#AddCloud(if Cloud_OBOS then crossover_overbought else Double.NaN,  crossunder_overbought, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
#addCloud(if Cloud_OBOS then crossover_oversold else Double.NaN, crossunder_oversold, GlobalColor("OSCloud"), GlobalColor("OSCloud"));

AddCloud(if Cloud_OBOS then z1 else Double.NaN, z2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
addCloud(if Cloud_OBOS then z5 else Double.NaN, z6, GlobalColor("OSCloud"), GlobalColor("OSCloud"));
#
 

Attachments

  • 00c-1.JPG
    00c-1.JPG
    101.3 KB · Views: 91
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

you can't just put a lower study on an upper chart and expect it to conform to the range of price bars. it is hard coded to plot numbers that are between 0 and 100.

this part that was added at the end, is setting numbers for cloud levels.
def OB1 = over_Bought;
def OB2 = highband;
def OS1 = over_Sold;
def OS2 = lowband;

you would have to compare the rsi to these levels. if it crosses one of them, then assign a price level to be plotted or used in a cloud.

here is an upper , that is somewhat converted from the pine code.


Code:
#upper_rsi_levels

#https://usethinkscript.com/threads/help-upper-level-rsi-support-resistance.18141/
#Help Upper Level RSI support/resistance
#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/.

#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;

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
def 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 -----------------


script f_getPrice {
#(_osc, _thresh, _cross) =>
 input _osc = 0;
 input _thresh = 0;
 #  down = 1 , both = 2 , up = 3
 input _cross = 0;
 def avgHigh = (high + close)/2;
 def avgLow  = (low + close)/2;
 def return_1 = if (_cross == 3 or _cross == 2) and (_osc crosses above _thresh) then avgHigh
   else if (_cross == 1 or _cross == 2) and (_osc crosses below _thresh) then avgLow
   else return_1[1];
 plot z = return_1;
}


#f_getPrice(_osc, _thresh, _cross) =>
#    avgHigh = math.avg(high, close)
#    avgLow  = math.avg(low , close)
#    var return_1 = 0.
#    if _cross == 'over' or _cross == 'both'
#        if ta.crossover(_osc, _thresh)
#            return_1 := avgHigh
#            return_1
#    if _cross == 'under' or _cross == 'both'
#        if ta.crossunder(_osc, _thresh)
#            return_1 := avgLow
#            return_1
#    return_1



# 'Overbought', minval=50, maxval=100
input i_obThreshold = 70;
#hint i_obThreshold: 'Overbought', minval=50, maxval=100
# 'Bull Zone' , minval=50, maxval=65
input i_bullZone    = 60;
# 'Bear Zone' , minval=35, maxval=50
input i_bearZone    = 40;
# ' Oversold' , minval=1 , maxval=50
input i_osThreshold = 30;


def i_obThreshold2 = if i_obThreshold < 50 then 50
  else if i_obThreshold > 100 then 100
  else i_obThreshold;
def i_bullZone2 = if i_bullZone < 50 then 50
  else if i_bullZone > 65 then 65
  else i_bullZone;
def i_bearZone2 = if i_bearZone < 35 then 35
  else if  i_bearZone > 50 then 50
  else i_bearZone;
def  i_osThreshold2 = if  i_osThreshold < 1 then 1
  else if  i_osThreshold > 50 then 50
  else  i_osThreshold;


#// -Calculations ════════════════════════════════════════════════════════════════════════════════ //
#oscillator = ta.rsi(i_source == 'Price (close)' ? close : ta.obv, i_length)
#  down = 1 , both = 2 , up = 3

def oscillator = rsi;
def crossover_overbought  = f_getPrice(oscillator, i_obThreshold2, 3);
def crossunder_overbought = f_getPrice(oscillator, i_obThreshold2, 1);
def bullZone              = f_getPrice(oscillator, i_bullZone2   , 2);
def bearZone              = f_getPrice(oscillator, i_bearZone2   , 2);
def crossover_oversold    = f_getPrice(oscillator, i_osThreshold2, 3);
def crossunder_oversold   = f_getPrice(oscillator, i_osThreshold2, 1);


addchartbubble(0, low,
 crossover_overbought + "\n" +
 crossunder_overbought + "\n" +
 bullZone + "\n" +
 bearZone + "\n" +
 crossover_oversold + "\n" +
 crossunder_oversold + "\n"
, color.yellow, no);


plot z1 = crossover_overbought;
plot z2 = crossunder_overbought;
plot z3 = bullZone;
plot z4 = bearZone;
plot z5 = crossover_oversold;
plot z6 = crossunder_oversold;
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.red);
z2.SetDefaultColor(Color.red);
z3.SetDefaultColor(Color.yellow);
z4.SetDefaultColor(Color.yellow);
z5.SetDefaultColor(Color.green);
z6.SetDefaultColor(Color.green);


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

DefineGlobalColor( "OBCloud", color.red);
DefineGlobalColor( "OSCloud", color.green);
DefineGlobalColor("Overbought", Color.light_GRAY);
DefineGlobalColor("Oversold", Color.light_GRAY);

#def OB1 = over_Bought;
#def OB2 = highband;
#def OS1 = over_Sold;
#def OS2 = lowband;
# over_Bought = 70;
# highband = 75;
# over_Sold = 30;
# lowband = 25;

input Cloud_OBOS = yes;
#AddCloud(if Cloud_OBOS then OB1 else Double.NaN, OB2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
#addCloud(if Cloud_OBOS then OS1 else Double.NaN, OS2, GlobalColor("OSCloud"), GlobalColor("OSCloud"));

# if enabled, kill the lines ?
#AddCloud(if Cloud_OBOS then crossover_overbought else Double.NaN,  crossunder_overbought, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
#addCloud(if Cloud_OBOS then crossover_oversold else Double.NaN, crossunder_oversold, GlobalColor("OSCloud"), GlobalColor("OSCloud"));

AddCloud(if Cloud_OBOS then z1 else Double.NaN, z2, GlobalColor("OBCloud"), GlobalColor("OBCloud"));
addCloud(if Cloud_OBOS then z5 else Double.NaN, z6, GlobalColor("OSCloud"), GlobalColor("OSCloud"));
#
Thank you @halcyonguy for the help!
 
@GoLo , if you are looking to identify potential S/R levels, probably ADX is a better tool than RSI. check when those marked signals appear, which represent peaks of trends. you might add code to point the price level it happens

http://tos.mx/3nfTQH6

View attachment 21389
I am not familiar with it. But do you think that there is no mistake here in your code? Thanks for sharing

Code:
plot Kick = Kicko[0];
plot KickL = Kicko[0];
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
355 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