Hello,
I am trying to customize the StochRSI indicator to change color when it goes to overbought and oversold.
I tried to use some of the code from this link and no luck.
https://usethinkscript.com/threads/adding-color-to-plots-labels-watchlists.6845/
If someone could assist that would be awesome.
Thank you!
#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#
declare lower;
input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_average_type = AverageType.WILDERS;
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising", CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear", CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
# ########################################################
def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type);
plot FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK;
plot FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD;
#RSI> RSI[1] this statement is saying if the current candle is greater than the previous candle
#that is what [1] denotes. Thus defining uptick. The same is then done for downticks.
RSI.AssignValueColor(
if RSI> over_bought then GlobalColor("maxxed") else
if RSI< OverSold then GlobalColor("pretrend") else
if RSI> RSI[1] then GlobalColor("rising")
else GlobalColor("bear"));
RSI.SetLineWeight(3);
# ########################################################
# ########################################################
plot OverBought = over_bought;
plot OverSold = OverSold;
plot UpArrow = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownArrow = if RSI crosses below OverBought then OverBought else Double.NaN;
DefineGlobalColor("OBcolor", CreateColor(171, 171, 225)) ;
DefineGlobalColor("OScolor", CreateColor(220, 220, 128)) ;
OverBought.SetDefaultColor(GlobalColor("OBcolor"));
OverSold.SetDefaultColor(GlobalColor("OScolor"));
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;
plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On FullK":
UpSignal = if upK then OverSold else Double.NaN;
DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
UpSignal = if upD then OverSold else Double.NaN;
DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
UpSignal = if upK or upD then OverSold else Double.NaN;
DownSignal = if downK or downD then OverBought else Double.NaN;
}
UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
AddLabel(show_label,
if RSI> over_bought then "RSI maxxed" else
if RSI< OverSold; then "RSI pre-trend" else
if RSI> RSI[1] then "RSI Trending " +round(RSI,2)
else "RSI Bear " +round(RSI,2) ,
if RSI> over_bought then GlobalColor("maxxed") else
if RSI< OverSold; and RSI>RSI[1] then GlobalColor("pretrend") else
if RSI> RSI[1] then GlobalColor("rising")
else GlobalColor("bear"));
AddCloud(if RSI >= over_bought then RSI else Double.NaN, over_bought,
GlobalColor("maxxed"), GlobalColor("maxxed"));
AddCloud(if RSI <= OverSold; then OverSold; else Double.NaN, RSI,
GlobalColor("pretrend"), GlobalColor("pretrend"));
# ########################################################