Cool Scripts: Create Your Own Dow-to-Gold Ratio

How to build a chart that displays the ratio of the Dow Jones Industrial average to the price of gold using thinkScript in the thinkorswim platform by TD Ameritrade

Print ratio
3 min read

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.



The Dow-to-Gold ratio (the lower indicator above) helps you see how overpriced the SPX (upper chart) might be relative to the ratio. For illustrative purposes only

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:

  1. #hint: Ratio Chart
  2. declare lower;
  3. Input symbol_1 = “/YM”;
  4. Input symbol_2 = “/GC”;
  5. Plot ratio = close(symbol_1) / close(symbol_2);
  6. ratio.AssignValueColor(if ratio >= ratio[1] 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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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!

Call Us

Market volatility, volume, and system availability may delay account access and trade executions.

Past performance of a security or strategy does not guarantee future results or success.

Options are not suitable for all investors as the special risks inherent to options trading may expose investors to potentially rapid and substantial losses. Options trading subject to TD Ameritrade review and approval. Please read Characteristics and Risks of Standardized Options before investing in options.

Supporting documentation for any claims, comparisons, statistics, or other technical data will be supplied upon request.

The information is not intended to be investment advice or construed as a recommendation or endorsement of any particular investment or investment strategy, and is for illustrative purposes only. Be sure to understand all risks involved with each strategy, including commission costs, before attempting to place any trade. Clients must consider all relevant risk factors, including their own personal financial situations, before trading.

This is not an offer or solicitation in any jurisdiction where we are not authorized to do business or where such offer or solicitation would be contrary to the local laws and regulations of that jurisdiction, including, but not limited to persons residing in Australia, Canada, Hong Kong, Japan, Saudi Arabia, Singapore, UK, and the countries of the European Union.

TD Ameritrade, Inc., member FINRA/SIPC. TD Ameritrade is a trademark jointly owned by TD Ameritrade IP Company, Inc. and The Toronto-Dominion Bank. © 2018 TD Ameritrade.

Scroll to Top