When asked to describe a widespread problem and then offer a solution I thought they meant for something like global warming. But alas, it was to solve a problem related to thinkorswim® using thinkScript®, the do-almost-anything-we-didn’t-think-of tool.
For my first trick, I want to show you how to build a chart that displays the ratio of the Dow Jones Industrial average to the price of gold. Despite the name, the “Dow-to-Gold Ratio” is used by many traders to tell how overpriced the S&P 500 (SPX) might be.
Referring to Figure 1 below, you can see historically as the SPX hit new highs, gold was also at highs, and the ratio remained relatively low. But at the time of writing, as SPX continues to rise, gold is going down. So SPX is becoming expensive valued in gold as well as U.S. dollars.
The Dow-to-gold ratio has been used to analyze everything from stock-market moves to predicting upcoming interest-rate decisions. We aren’t going to delve into Dow-to-gold theories, but rather describe how to see this ratio on thinkorswim. The problem we face is you can’t enter ratios in the symbol entry box on thinkorswim. So we need to think outside the (symbol entry) box to solve this one.
Starting on the thinkorswim Charts tab, bring up a one-year daily chart of the S&P 500 index by entering SPX in the symbol box. We’re going to build a study for a lower sub-graph of the chart in which the displayed data will be independent of the charted symbol—meaning, you can change the symbol without changing the new study. Once you see an SPX chart, fire up the thinkScript Editor by following the sidebar “Scripting from the Charts.” Then enter the following script:
- #hint: Ratio Chart
- declare lower;
- Input symbol_1 = “/YM”;
- Input symbol_2 = “/GC”;
- Plot ratio = close(symbol_1) / close(symbol_2);
- ratio.AssignValueColor(if ratio >= ratio then Color.UPTICK else Color.DOWNTICK);
After you’ve entered the above code, press Apply and OK and you’ll see a chart similar to Figure 2, with the Dow-to-gold indicator at the bottom.
Now let’s break down the code line by line to help you figure out how you got there.
- Line one is a note which doesn’t affect your script but is used to keep track of each section’s goal. In our example we created “fancy note” by using the key word hint. This tells the thinkScript Editor to place the little help bubble next to our custom script in the Edit Studies and Strategies.
- Line two tells the script this is a study by default that belongs on a lower subgraph. This is used with studies that don’t relate, or will not scale, to the chart’s price graph.
- Lines three and four allow you to change the raio symbols without editing the script. You can customize these two inputs in the study parameters similar to how you customize pre-defined studies. Since we are building the Dow-to-gold ratio, I used the futures for each of these specific products.
- Line five is the math, the heart and soul of the script. We are simply taking the first input symbol and dividing it by the second, thus making it a ratio.
- Line six makes the study pretty. The Assign Value-Color function allows us to color the line as the ratio changes. If the ratio moves up, we color the line as our Uptick. And if it moves down, as our Downtick.
Congrats, you have your own Dow-to-gold ratio chart. And since you solved this in a smart way, you now create any ratio chart you desire simply by editing the symbols in lines 3 and 4. We may not have solved global warming today, but we did make one small step for a legion of traders!