# Indicator for an Indicator (ROC of RSI)

#### Garamond

##### New member
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 . . .

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

@Garamond try
Ruby:
``````declare lower;

input length = 14;
input colorNormLength = 14;
def price = reference RSI.RSI;

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);
ZeroLine.SetDefaultColor(GetColor(5));``````

Last edited:
@Garamond try
Ruby:
``````declare lower;

input length = 14;
input colorNormLength = 14;
input price = reference RSI.RSI;

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);
ZeroLine.SetDefaultColor(GetColor(5));``````
what does nput price = reference RSI.RSI; means?

@majidg
Typo on my part, should be def not input. Have updated my previous post.
This will assign the RSI ouptut of the first study to the price variable of the second study. So now ROC is being calculated using RSI instead of close.

"Reference" -- that's what I needed. Thanks, Svanoy. I'll go try this out now.

Can I ask how the period is functioning between the two RSIs?

I noticed the script works regardless of whether you use "reference RSI.RSI" or just "reference RSI".

Thanks.

Can I ask how the period is functioning between the two RSIs?

I noticed the script works regardless of whether you use "reference RSI.RSI" or just "reference RSI".

Thanks.
If you don't put a period and the name of a specific variable. ThinkScript defaults to using the first variable in the study.
So "reference RSI.RSI" or just "reference RSI" provide the same results because RSI is the 1st variable defined in the study.

@Garamond
RSI is the name of the study and also the name of the variable being referenced in the study.

87k+ Posts
333 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?