Paint candle border based on RSI

BullParagon

New member
I am sure this has been done before, but I can not find it. I am looking to paint just border of the candle based on the RSI. I want to add this to a script that paints candles based other attributes.
Here is my goal:
RSI under 30: Red
RSI 30-50: Orange
RSI 50-70: Green
RSI over 70 Yellow

Also looking for a chart indicator that will show me when RSI has changed by a certain percentage (20%). Example if RSI went from 30 to 36, I would like an arrow or other indicator to plot.

Thanks in advance for any help.
 
Solution
I am sure this has been done before, but I can not find it. I am looking to paint just border of the candle based on the RSI. I want to add this to a script that paints candles based other attributes.
Here is my goal:
RSI under 30: Red
RSI 30-50: Orange
RSI 50-70: Green
RSI over 70 Yellow

Also looking for a chart indicator that will show me when RSI has changed by a certain percentage (20%). Example if RSI went from 30 to 36, I would like an arrow or other indicator to plot.

Thanks in advance for any help.


draw colored rectangles around the candles based on RSI value.
...can adjust the height. default is 2 ticks, so border is slightly larger than candle.
...0 = same height as candle

draws arrows based on RSI value, %...
I am sure this has been done before, but I can not find it. I am looking to paint just border of the candle based on the RSI. I want to add this to a script that paints candles based other attributes.
Here is my goal:
RSI under 30: Red
RSI 30-50: Orange
RSI 50-70: Green
RSI over 70 Yellow

Also looking for a chart indicator that will show me when RSI has changed by a certain percentage (20%). Example if RSI went from 30 to 36, I would like an arrow or other indicator to plot.

Thanks in advance for any help.


draw colored rectangles around the candles based on RSI value.
...can adjust the height. default is 2 ticks, so border is slightly larger than candle.
...0 = same height as candle

draws arrows based on RSI value, % change, bar to bar.
...default placement is 1 tick below border.
(i like to separate shapes. i think it makes them easier to see)

RSI under 30: Red
RSI 30-50: Orange
RSI 50-70: Green
RSI over 70 Yellow

when RSI has changed by a percentage (20%)
if RSI went from 30 to 36, I would like an arrow or other indicator to plot.


Code:
# rsi_candle_border_color_addchart

#https://usethinkscript.com/threads/paint-candle-border-based-on-rsi.15275/
#Paint candle border based on RSI

def na = double.nan;
def bn = barnumber();

#------------------------------
# RSI
# TD Ameritrade IP Company, Inc. (c) 2007-2023
#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;

def RSI = 50 * (ChgRatio + 1);
def 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);

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

#RSI over 70 Yellow
#RSI 50-70: Green
#RSI 30-50: Orange 
#RSI under 30: Red

input rsi_level1 = 30;
input rsi_level2 = 50;
input rsi_level3 = 70;

DefineGlobalColor("color1", color.red);
DefineGlobalColor("color2", color.orange);
DefineGlobalColor("color3", color.green);
DefineGlobalColor("color4", color.yellow);
# GlobalColor("color1")

#DefineGlobalColor("Gray", CreateColor(28, 28, 28));  #Gray
# GlobalColor("x")

def zone1 = (rsi < rsi_level1);
def zone2 = (rsi >= rsi_level1 and rsi < rsi_level2);
def zone3 = (rsi >= rsi_level2 and rsi < rsi_level3);
def zone4 = (rsi >= rsi_level3);


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

#yellow outline, addchart()
#https://usethinkscript.com/threads/draw-a-box-around-the-overnight-session-on-futures-intraday-charts.2087/page-3#post-58481
#sleepyz


input bar_outline_factor = 2;
#hint bar_outline_factor: adjust the height of the colored border. \n0 = original candle height. multiples of ticksize.

def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;

def h0 = h + TickSize() * bar_outline_factor;
def l0 = l - TickSize() * bar_outline_factor;

#-----------------------
# zone1  rsi<30
def h1 = if zone1 then h0 else nan;
def l1 = if zone1 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o1 = if zone1 then h1 else nan;
def c1 = if zone1 then l1 else nan;

# solid ,  open = low , close = high  , is solid
#def o1 = if cond then l1 else nan;
#def c1 = if cond then h1 else nan;

AddChart(growcolor = GlobalColor("color1"), high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);

#-----------------------
# zone2  rsi , 30 to 50
def h2 = if zone2 then h0 else nan;
def l2 = if zone2 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o2 = if zone2 then h2 else nan;
def c2 = if zone2 then l2 else nan;

AddChart(growcolor = GlobalColor("color2"), high = h2, low = l2, open = c2, close = o2, type = ChartType.CANDLE);

#-----------------------
# zone3  rsi , 50 to 70
def h3 = if zone3 then h0 else nan;
def l3 = if zone3 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o3 = if zone3 then h3 else nan;
def c3 = if zone3 then l3 else nan;

AddChart(growcolor = GlobalColor("color3"), high = h3, low = l3, open = c3, close = o3, type = ChartType.CANDLE);

#-----------------------
# zone4  rsi > 70
def h4 = if zone4 then h0 else nan;
def l4 = if zone4 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o4 = if zone4 then h4 else nan;
def c4 = if zone4 then l4 else nan;

AddChart(growcolor = GlobalColor("color4"), high = h4, low = l4, open = c4, close = o4, type = ChartType.CANDLE);

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

# RSI % chg , bar to bar
# show when RSI has changed by a percentage (20%)
#  Example if RSI went from 30 to 36, I would like an arrow or other indicator to plot.

# plot arrows 1 tick away from border
def y = 1;
input min_rsi_change_percent = 20.0;
def rsiper = round(100*(rsi-rsi[1])/rsi[1],1);

plot zperup = if (rsiper >= min_rsi_change_percent) then (l0 - (TickSize() * y)) else na;
zperup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zperup.SetDefaultColor(Color.green);
zperup.setlineweight(4);
zperup.hidebubble();

plot zperdwn = if (rsiper <= -min_rsi_change_percent) then (h0 + (TickSize() * y)) else na;
zperdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zperdwn.SetDefaultColor(Color.red);
zperdwn.setlineweight(4);
zperdwn.hidebubble();


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

input test_lines = no;
addverticalline(test_lines and zone1, "-", GlobalColor("color1"));
addverticalline(test_lines and zone2, "-", GlobalColor("color2"));
addverticalline(test_lines and zone3, "-", GlobalColor("color3"));
addverticalline(test_lines and zone4, "-", GlobalColor("color4"));
#

colored borders based on RSI value.
the candle borders are slightly taller than the candles because
bar_outline_factor = 2
arrows show when RSI changed more than 20%
GM 1 min 5/5
Whp7gaW.jpg
 
Solution
draw colored rectangles around the candles based on RSI value.
...can adjust the height. default is 2 ticks, so border is slightly larger than candle.
...0 = same height as candle

draws arrows based on RSI value, % change, bar to bar.
...default placement is 1 tick below border.
(i like to separate shapes. i think it makes them easier to see)

RSI under 30: Red
RSI 30-50: Orange
RSI 50-70: Green
RSI over 70 Yellow

when RSI has changed by a percentage (20%)
if RSI went from 30 to 36, I would like an arrow or other indicator to plot.


Code:
# rsi_candle_border_color_addchart

#https://usethinkscript.com/threads/paint-candle-border-based-on-rsi.15275/
#Paint candle border based on RSI

def na = double.nan;
def bn = barnumber();

#------------------------------
# RSI
# TD Ameritrade IP Company, Inc. (c) 2007-2023
#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;

def RSI = 50 * (ChgRatio + 1);
def 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);

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

#RSI over 70 Yellow
#RSI 50-70: Green
#RSI 30-50: Orange
#RSI under 30: Red

input rsi_level1 = 30;
input rsi_level2 = 50;
input rsi_level3 = 70;

DefineGlobalColor("color1", color.red);
DefineGlobalColor("color2", color.orange);
DefineGlobalColor("color3", color.green);
DefineGlobalColor("color4", color.yellow);
# GlobalColor("color1")

#DefineGlobalColor("Gray", CreateColor(28, 28, 28));  #Gray
# GlobalColor("x")

def zone1 = (rsi < rsi_level1);
def zone2 = (rsi >= rsi_level1 and rsi < rsi_level2);
def zone3 = (rsi >= rsi_level2 and rsi < rsi_level3);
def zone4 = (rsi >= rsi_level3);


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

#yellow outline, addchart()
#https://usethinkscript.com/threads/draw-a-box-around-the-overnight-session-on-futures-intraday-charts.2087/page-3#post-58481
#sleepyz


input bar_outline_factor = 2;
#hint bar_outline_factor: adjust the height of the colored border. \n0 = original candle height. multiples of ticksize.

def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;

def h0 = h + TickSize() * bar_outline_factor;
def l0 = l - TickSize() * bar_outline_factor;

#-----------------------
# zone1  rsi<30
def h1 = if zone1 then h0 else nan;
def l1 = if zone1 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o1 = if zone1 then h1 else nan;
def c1 = if zone1 then l1 else nan;

# solid ,  open = low , close = high  , is solid
#def o1 = if cond then l1 else nan;
#def c1 = if cond then h1 else nan;

AddChart(growcolor = GlobalColor("color1"), high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);

#-----------------------
# zone2  rsi , 30 to 50
def h2 = if zone2 then h0 else nan;
def l2 = if zone2 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o2 = if zone2 then h2 else nan;
def c2 = if zone2 then l2 else nan;

AddChart(growcolor = GlobalColor("color2"), high = h2, low = l2, open = c2, close = o2, type = ChartType.CANDLE);

#-----------------------
# zone3  rsi , 50 to 70
def h3 = if zone3 then h0 else nan;
def l3 = if zone3 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o3 = if zone3 then h3 else nan;
def c3 = if zone3 then l3 else nan;

AddChart(growcolor = GlobalColor("color3"), high = h3, low = l3, open = c3, close = o3, type = ChartType.CANDLE);

#-----------------------
# zone4  rsi > 70
def h4 = if zone4 then h0 else nan;
def l4 = if zone4 then l0 else nan;

# hollow ,  open = high , close = low  , is hollow
def o4 = if zone4 then h4 else nan;
def c4 = if zone4 then l4 else nan;

AddChart(growcolor = GlobalColor("color4"), high = h4, low = l4, open = c4, close = o4, type = ChartType.CANDLE);

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

# RSI % chg , bar to bar
# show when RSI has changed by a percentage (20%)
#  Example if RSI went from 30 to 36, I would like an arrow or other indicator to plot.

# plot arrows 1 tick away from border
def y = 1;
input min_rsi_change_percent = 20.0;
def rsiper = round(100*(rsi-rsi[1])/rsi[1],1);

plot zperup = if (rsiper >= min_rsi_change_percent) then (l0 - (TickSize() * y)) else na;
zperup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zperup.SetDefaultColor(Color.green);
zperup.setlineweight(4);
zperup.hidebubble();

plot zperdwn = if (rsiper <= -min_rsi_change_percent) then (h0 + (TickSize() * y)) else na;
zperdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zperdwn.SetDefaultColor(Color.red);
zperdwn.setlineweight(4);
zperdwn.hidebubble();


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

input test_lines = no;
addverticalline(test_lines and zone1, "-", GlobalColor("color1"));
addverticalline(test_lines and zone2, "-", GlobalColor("color2"));
addverticalline(test_lines and zone3, "-", GlobalColor("color3"));
addverticalline(test_lines and zone4, "-", GlobalColor("color4"));
#

colored borders based on RSI value.
the candle borders are slightly taller than the candles because
bar_outline_factor = 2
arrows show when RSI changed more than 20%
GM 1 min 5/5
Whp7gaW.jpg
great job @halcyonguy , can you also do the same script but with out the candle border? thank you in advance. keep up the good job
 

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