Adding Index to Stock Chart Pane

First I would like to thank everyone for your help; this is really such a great resource.

I am trying to manually add an index or second stock chart within the same chart for comparison. (So I would like to add a chart of the S&P 500 or MSFT to a daily chart of AAPL for example.) I did not see anything listed in the manual or in this forum. Is there a formal name for this? Maybe I searched for the wrong term.

For now I am just working on my knowledge of the charting features then I will dive deeper into the nuts and bolts of coding.

Thank you again,

Tom

@tgiann3, Welcome to the AmiBroker Forum.

Your best resource is the help file / manual / User's Guide..

As you are getting up to speed, it can sometimes be a challenge to know the proper terminology to search for.

I suggest that you go through the Help -> Help Contents - Make sure the Contents Tab is selected, then navigate to:
User's Guide - AmiBroker Formula Language
Then look at the Alphabetical list of AFL Functions AND the Categorized list of AFL functions.

For this issue, I suspect you need the "Foreign" function to get the data of the second stock/index. When you assign the foreign value to a variable, you can then plot it on the same sheet and pane as your original. Watch out for the parameters in the Plot statement.

1 Like

Is there a way to do it through the GUI?

Yes, Go to charts > Basic charts Folder

Under that look for the Formula file Price (foreign)

Drag it onto your chart pane where you need to plot the second symbol.
Then choose the desired symbol from the parameters window.

If you look at the formula, the key function here is PlotForeign()
https://www.amibroker.com/guide/afl/plotforeign.html
This is what gets the job done. Infact you can add a few of these and compare more than 2 symbols.

1 Like

Recommended reading http://www.amibroker.com/guide/h_dragdrop.html

Also add to nsm51, the “Relative Performance” built in chart is a handy tool for comparing.

Outstanding. Thank you very much!