Overlay chart in same AB pane scaling the overlay to match the price differences

/* Onto an AB pane displaying a ticker bar chart I want to overlay an S&P indice line chart so to visually compare recent performances over say 6 months.
Ticker prices are just a fraction of the S&P indice prices so I need to scale down the S&P Indice to match each Ticker Prices scale.
 I think that taking an average of the past 130 days S&P values and dividing the sum of that into the ticker lastvalue(c) value would scale the S&P down nicely but I can’t code this to work.  How can I do this?
What I have: */
Days = Sum(C,130)/130;
MyOverlay = ( Foreign("XAO", "C")); 
Fraction = Days /MyOverlay;
Plot(Foreign("XAO", "C")*Fraction, "AXO", Fraction,styleline) ;  // Info Tech   
// But this computes the Sum Ticker and not the S&P

Before you get into your own scaling Math, did you checkout the built-in options available for Plot()

Try some of these scaling options that suit you styleOwnScale or styleLeftAxisScale

https://www.amibroker.com/guide/afl/plot.html

1 Like

/* Thanks for your help Travis. As you know I am still learning but have since tried the Plot Command including styleLeftAxisScale with the following conclusions: ``

The PlotForeign command does not create an actual LHS scale but rather uses an imaginary scale that seems to work fine for overlaying indicators that use the same ticker data. ``

When I added Plot Foreign S&P data it produced an undesirable effect. ``

It changed to RHS scale so that its scale matched the Foreign S&P data range which left the ticker graph as a flat straight line.

`I was able to scale the Foreign S&P
data back to share the same scale of the ticker but that result was not
suitable so my objective is flawed */

PlotForeign( "TICKER", "", colorDefault, styleBar | styleOwnScale);

This simple code works for me.
Remember, it is styleOwnScale so the Right Y-axis is not relevant but it gives the overlap you seem to be looking for.

1 Like

Thanks travick, I am now using your suggestion