Add Label to display MACD, RSI values of a different symbol

scriptstudent

New member
Hi, I want to display the MACD, RSI values of ANOTHER ticker symbol as a LABEL in my current chart.
I am trying to accomplish something like the following:
def rel = reference RSI("SPX", 14).rsi;
Do study functions like MACD, RSI accept ticker symbol as input?
Please help on how to code it in thinkscript? Thanks.
 
Last edited:
Solution
Hi, I want to display the MACD, RSI values of ANOTHER ticker symbol as a LABEL in my current chart.
I am trying to accomplish something like the following:
def rel = reference RSI("SPX", 14).rsi;
Do study functions like MACD, RSI accept ticker symbol as input?
Please help on how to code it in thinkscript? Thanks.

RSI has an input for a price, but MACD does not.

i copied both studies and pasted them into a new study, and modified them to use price data from a different symbol
there are 3 labels to show the symbol, MACD, RSI
can choose to show the study lines or not.

Code:
# sym1_macd_rsi_00


# https://usethinkscript.com/threads/add-label-to-display-macd-rsi-values-of-a-different-symbol.12695/
# Add Label to...
Hi, I want to display the MACD, RSI values of ANOTHER ticker symbol as a LABEL in my current chart.
I am trying to accomplish something like the following:
def rel = reference RSI("SPX", 14).rsi;
Do study functions like MACD, RSI accept ticker symbol as input?
Please help on how to code it in thinkscript? Thanks.

RSI has an input for a price, but MACD does not.

i copied both studies and pasted them into a new study, and modified them to use price data from a different symbol
there are 3 labels to show the symbol, MACD, RSI
can choose to show the study lines or not.

Code:
# sym1_macd_rsi_00


# https://usethinkscript.com/threads/add-label-to-display-macd-rsi-values-of-a-different-symbol.12695/
# Add Label to display MACD, RSI values of a different symbol

declare lower;

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

input symbol1 = "SPY";
def price1 = close(symbol1);

input show_plots = no;

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

# macd
# TD Ameritrade IP Company, Inc. (c) 2007-2022

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input macd_averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

#plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Value = MovingAverage(macd_averageType, price1, fastLength) - MovingAverage(macd_averageType, price1, slowLength);
def Avg = MovingAverage(macd_averageType, Value, MACDLength);


plot ZValue = value;
plot ZAvg = avg;

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

zvalue.sethiding(!show_plots);
zavg.sethiding(!show_plots);
diff.sethiding(!show_plots);
zeroline.sethiding(!show_plots);
upsignal.sethiding(!show_plots);
downsignal.sethiding(!show_plots);


UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

zValue.SetDefaultColor(GetColor(1));
zAvg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

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


# 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 rsi_averageType = AverageType.WILDERS;
input rsi_showBreakoutSignals = no;

def NetChgAvg = MovingAverage(rsi_averageType, price - price[1], length);
def TotChgAvg = MovingAverage(rsi_averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot zRSI = rsi;
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot rUpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot rDownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

zrsi.sethiding(!show_plots);
oversold.sethiding(!show_plots);
overbought.sethiding(!show_plots);
rUpSignal.sethiding(!show_plots);
rDownSignal.sethiding(!show_plots);


rUpSignal.SetHiding(!showBreakoutSignals);
rDownSignal.SetHiding(!showBreakoutSignals);

zRSI.DefineColor("OverBought", GetColor(5));
zRSI.DefineColor("Normal", GetColor(7));
zRSI.DefineColor("OverSold", GetColor(1));
zRSI.AssignValueColor(if RSI > over_Bought then zRSI.color("OverBought") else if RSI < over_Sold then zRSI.color("OverSold") else zRSI.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);

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

addlabel(1, symbol1, color.yellow);
addlabel(1, "MACD " + round(value,2), color.yellow);
addlabel(1, "RSI " + round(rsi,2), color.yellow);
#
 
Solution

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