Ratio of indicators instead of stock prices

vgt2101

New member
I would like to plot the ratio of the results of an indicator between two different stocks/ticker symbols. Meaning the ratio of SPY's RSI (21) / MSFT's RSI (21) as an example. In this example, SPY and MSFT are stocks/ticker symbols, RSI is an indicator, and (21) is the amount of days for the indicator.
 
Solution
Code:
declare lower;
def MSFT = RSI(21,price = close("MSFT"));
def SPY = RSI(21,price = close("SPY"));
plot Ratio = SPY / MSFT;
Code:
declare lower;
def MSFT = RSI(21,price = close("MSFT"));
def SPY = RSI(21,price = close("SPY"));
plot Ratio = SPY / MSFT;
 
Solution
Code:
declare lower;
def MSFT = RSI(21,price = close("MSFT"));
def SPY = RSI(21,price = close("SPY"));
plot Ratio = SPY / MSFT;
it always shows same rsi for MSFT and SPY or any other symbol?
the label for SPY and MSFT or any other symbol compare to SPY always show the same number, Can you please help to fix this to show actual RSI value for both?
 
it always shows same rsi for MSFT and SPY or any other symbol?
the label for SPY and MSFT or any other symbol compare to SPY always show the same number, Can you please help to fix this to show actual RSI value for both?
he created a study to do exactly what you asked for.
if you want something different, ask a different question.
what do you want to see?
 
he created a study to do exactly what you asked for.
if you want something different, ask a different question.
what do you want to see?
Can the same code be created for the money flow index? So I'd like to see the plot of SPY's Money Flow Index period 21 : MSFT's Money Flow Index period 21.
 
So I'd like to see the plot of SPY's Money Flow Index period 21 : MSFT's Money Flow Index period 21. I would like to plot the ratio of the results of an indicator between two different stocks/ticker symbols.
 
Upon further review, it would appear that my previous reply did not properly address @vgt2101's request...Further testing has yielded the following script that I believe does find the correct ratio:

Code:
declare lower;

script mfi {
    input length = 21;
    input movingAvgLength = 1;
    input symbol  = "SPY";

    plot MoneyFlowIndex = Average(moneyflow(high(symbol), close(symbol), low(symbol), volume(symbol), length), movingAvgLength);
}

input symbol1 = "SPY";
input symbol2 = "MSFT";

def s1  = mfi(symbol = symbol1);
def s2  = mfi(symbol = symbol2);

def sym1 = if IsNaN(s1) then s1[1] else s1;
def sym2 = if IsNaN(s2) then s2[1] else s2;

plot Ratio = sym1 / sym2;

Hope this helps...

Good Luck and Good Trading :cool:
 
Upon further review, it would appear that my previous reply did not properly address @vgt2101's request...Further testing has yielded the following script that I believe does find the correct ratio:

Code:
declare lower;

script mfi {
    input length = 21;
    input movingAvgLength = 1;
    input symbol  = "SPY";

    plot MoneyFlowIndex = Average(moneyflow(high(symbol), close(symbol), low(symbol), volume(symbol), length), movingAvgLength);
}

input symbol1 = "SPY";
input symbol2 = "MSFT";

def s1  = mfi(symbol = symbol1);
def s2  = mfi(symbol = symbol2);

def sym1 = if IsNaN(s1) then s1[1] else s1;
def sym2 = if IsNaN(s2) then s2[1] else s2;

plot Ratio = sym1 / sym2;

Hope this helps...

Good Luck and Good Trading :cool:
what can be done to make symbol2 to be any symbol? when I put getsymbol() for "MSFT" I am not able to add label, or label will disappear.
 

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