MA distance from Price

I would appreciate if I would be helped on this. I would like to Plot a simple moving average lets say SMA 50 .Then I want to plot the value of SMA next to the line itself instead of on Y-Axis.I will be using the "END' key to create space on the right between the price bars and the Y-Axis.After the MA value,I would like to plot in brackets how far away the price is from the MA and this should be dynamically updated as price changes in live market.

So the final output would be something like this 120 (8),where 120 is the MA value and 8 is the distance from price at this instant.

Have you tried to code the above? if yes provide the code.
You need to put your effort first.

4 Likes

I managed to find some code that will display the distance from the MA in the bottom pane in a histogram. However,I want it display the distance right next to the moving average itself on the chart pane. Any inputs will be appreciated.

ma200 = MA(Close, 200);

distancia = (Close-ma200)/Close * 100;

cero = IIf(Close >= ma200, colorGreen, colorRed);

Plot( distancia, "distancia", cero, styleHistogram | styleThick, Null, Null, 0, 1, 5 );

Attaching a picture for the desired output.In the Picture 77.38 is the MA value and (0.64) is the current distance from Price.

Do all the calculation , format the result and output it using
https://www.amibroker.com/guide/afl/plottext.html

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.