reverse calculating a moving average

 

I want to write a function that i can input the periods and a price from a bar on the historical chart, so the function will output the value of where a moving average would have been when the price was at that level, I was thinking this must have been done before for analysing short period MA crossovers etc, although I couldnt find anything while searching, so before i set about reverse engineering the moving average code myself does anyone know if such code already exists ?

 

Code for moving average indicator is https://www.mql5.com/en/code/7534

 

Note that there are many ways of calc'ing MAs, and each has a different way to do what you want.

Note also that there are many prices that can be used to calc MAs.

For each way, there is a way to work out how the MA value changes as a particular bar price changes its value.
I myself have used this to technique to set up Buy levels before the event. i.e. Converting "When MA move to X then trigger order" into "When price moves to Y then trigger order".

Reason: