#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

 Difficulty All Easy Intermediate Advanced Section All Application Charting Indicators Watchlist Screener Downloader Composite Analysis Simulator Portfolio Pivot Table Artificial Intelligence
How to plot the ratio of two stocks

Updated on 2011-07-15 06:15:20

To plot the ratio of two stocks or any other assets, we need to use the close price of the active symbol and divide it by the price of a referenced symbol.
There are several functions we can use to reference an external symbol. The most obvious one is: GetSeries.

Steps:
- Right click on a chart then select "Create new pane"
- Click on "Add Indicator" icon (Top-Left corner of the new pane)
- Select Operation tab
- In the first input box, type: close
- In the second input box, click on "Add", select "External Symbol", type a ticker name (next to "Select a Symbol") then click on "OK"
- Select the division (/) operator
- Click on "OK" to add the "ratio of two stocks" indicator

You can edit the previously created formula by right clicking on the pane then selecting "Edit Formula"

Here is the formula:
op1 = close / GetSeries('AA', Close);
Plot(op1, 'Operation', colorBlack, ChartLine, StyleSymbolNone);

You can change the formula title by changing the formula to:
symbol1 = "AA";
op1 = close / GetSeries(symbol1, Close);
Plot(op1, name()."/".symbol1, colorBlack, ChartLine, StyleSymbolNone);

 Other how-to articles