How to PlotForeign symbol with indicator below price pane?

Hi all,

my goal is to plot some index (e. g. NASDAQ Composite) as an indicator below the standard price pane. This works fine with:

PlotForeign("^IXIC", "NASDAQ Composite", colorBlack);

Now, I want to add a moving average around the index:

PlotForeign("^IXIC", "NASDAQ Composite", colorBlack);
Plot(MA(Foreign("^IXIC", "C"), 200), "SMA", colorBlue);

This gave me:
plot_foreign_problem

The upper panel shows the price of the Nasdaq Composite with a moving average (orange line). The lower panel is the output of the above code. Both panels should show the same. However, in the lower panel the moving average is wrongly plotted.

What is wrong with my above code?

Thanks for your help!

Best, Axel

You should carefully read documentation of PlotForeign.
https://www.amibroker.com/guide/afl/plotforeign.html

If you do not define a style in that function then the default style of that function is used which is

styleCandle | styleOwnscale

So then PlotForeign is using independent scaling compared to any other plots because of styleOwnScale


So if you do not want to plot with independent scaling then you have to define style in PlotForeign's fourth argument that does not add styleOwnScale, i.e.

PlotForeign("^IXIC", "NASDAQ Composite", colorBlack, styleCandle);
Plot(MA(Foreign("^IXIC", "C"), 200), "SMA", colorBlue);

if you want to independently overlay both (price and MA) on some other plot (and both price and MA of ^IXIC using same scale) then

PlotForeign("^IXIC", "NASDAQ Composite", colorBlack, styleCandle|styleLeftAxisScale);
Plot(MA(Foreign("^IXIC", "C"), 200), "SMA", colorBlue, styleLeftAxisScale);
4 Likes

Thank you very much for your help!

1 Like