I've gone through the tutorial and written some basic scripts. But this has perplexed me. I'd like to write a script to show me the Rate of Change of the RSI. Here are the two scripts. First RSI . . .
Now Rate of Change . . .
But how exactly do I combine these to get the ROC of the RSI? It's not clear to me how to tell the ROC indicator that it should be deriving its values from the RSI and not the price of the security. I'm guessing I need to include a definition of some sort.
Thank you!
#
# 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);
Now Rate of Change . . .
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
declare lower;
input length = 14;
input colorNormLength = 14;
input price = close;
assert(length > 0, "'length' must be positive: " + length);
plot ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot ZeroLine = 0;
ROC.DefineColor("Highest", Color.YELLOW);
ROC.DefineColor("Lowest", Color.LIGHT_RED);
ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));
But how exactly do I combine these to get the ROC of the RSI? It's not clear to me how to tell the ROC indicator that it should be deriving its values from the RSI and not the price of the security. I'm guessing I need to include a definition of some sort.
Thank you!