Chart a ratio of 2 index?

johnnyrocker

New member
Newbie question here.

I’d like to chart the VIX / VXv ratio.

on stockcharts.com I can use $VIX:$VXV Is something similar possible with a script?

efak57X.jpg
 
Definitely possible but I don't think it's that simple on ThinkorSwim.

What you can do is use the code below (credit to @generic) and then select the 2 tickers of your choosing:

Code:
input tickerA = "SPY";
input tickerB = "VIX";

def ticker1 = close(symbol = tickerA, period = agg);
def ticker2 = close(symbol = tickerB, period = agg);

plot ratio = ticker1 / ticker2;
 
Hey @johnnyrocker - I had similar questions recently. Another way to go about this is as follows: Think or Swim allows you to define "composite symbols" where you can add or subtract two tickers together. See Learning Center - Composite Symbols (thinkorswim.com) So if you are in charts, you could graph (Ticker1) + (Ticker2) etc. Once you have that graph, you can go to studies, and select the study "PairRatio" This gives you the ratio of the two securities that are part of your composite security. Hope that helps.
 
SHTidAF.png


@BenTen, this would be great, I found a script that makes an indicator concerning this thread.... I changed the old TOS VXV with the updated ticker VIX3m and thought that would fixt the issue. But I'm not seeing the indicator on my chart.... any thoughts?
 
Last edited by a moderator:
Definitely possible but I don't think it's that simple on ThinkorSwim.

What you can do is use the code below (credit to @generic) and then select the 2 tickers of your choosing:

Code:
input tickerA = "SPY";
input tickerB = "VIX";

def ticker1 = close(symbol = tickerA, period = agg);
def ticker2 = close(symbol = tickerB, period = agg);

plot ratio = ticker1 / ticker2;
A newbie here. I typed in the code, but not sure how to: credit to @generic)? For whatever reason, I got red errors when I typed in "agg", but if I changed to a number I got no error, but got a NA in the title of the code after the listed symbols in the header below the blue bar above the chart? My intent was to create a ratio that would compare the NYSE New Highs for one month ($NYHI1M) to NYSE New Lows for one month ($NYLO1M). I also wanted to create a ratio for the Cumulative NYSE New Highs for one month to the Cumulative NYSE New Lows for one month (but never found an indicator for these?). I am wondering in indicators can not be used to replace symbols, thus the reason I was interested in this "ticker" scenario. Looking forward to learn more!
 
This will do the job. it uses symbol1:symbol2 ratio in creating an oscillator.
"input MAperiodicity = 6;" Adjust to upscale intraday data to daily or higher order
----------------------------
#(c) Harapa

declare lower;
input symbol1 = "SPY";
input symbol2 = "VIX";
input price1 = FundamentalType.CLOSE;
input price2 = FundamentalType.CLOSE;
input colorNormLength = 3;
input fastLength = 19;
input slowLength = 39;
input MAperiodicity = 6;
input averageType = AverageType.EXPONENTIAL;
input direction = -1;

def Ratio = (Fundamental(price1, symbol1)) / (Fundamental(price2, symbol2));
def FastAvg = MovingAverage(averageType, Ratio, fastLength*MAperiodicity);
def SlowAvg = MovingAverage(averageType, Ratio, slowLength*MAperiodicity);


plot Oscillator = (FastAvg - SlowAvg)*direction;

Oscillator.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Oscillator.assignValueColor(if Oscillator > 0 and Oscillator > Oscillator[1] then color.DARK_GREEN else if Oscillator > 0 and Oscillator < Oscillator[1] then color.PINK else if Oscillator < 0 and Oscillator < Oscillator[1] then color.RED else color.Green);
;
 

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