Extrapolating moving average to the future.

 

Hello there. I coded an expert advisor that takes and manages trades based on moving averages. Furthermore, it notifies users on new entries and trailing stop levels. The program is hosted by me and it uses a mail service to notify everyone on every move. Now I want to improve it a little further by using pending orders. The current system uses market execution and the trades are almost instant and people tend to miss some signals. 

I need to predict future values of moving averages since the instrument I trade allows movement in one direction, long enough to obtain reliable future data. Tick volume is almost the same. And thus M1 timeframe candles have almost similar sizes. So based on the M1 candles, it is possible to estimate future candle close prices and thus obtain reliable moving average values into the future. 

Here is a chart sample of what I'm talking about.

https://www.mql5.com/en/charts/15602466/crash-1000-index-m1-deriv-limited

By estimating moving averages, I can estimate future limit order taking points. Then I will figure out how to manage the levels if drastic changes occur before the zone is reached.

The IMA() function, at least to my understanding, takes care of historical data from the index that corresponds to the moving average period to the current candle index. I know there must be a way to extrapolate it into the future but I haven't figured it out.

So I decided to calculate a simple moving average manually as per the code below taken from one of the articles in the community.

if (rates_total < MAPeriod - 1 + begin)
    return(0);
   
   //---- declaration of local variables 
   int first, bar, start;
   double Sum, SMA;
   
   //---- calculation of starting index first of the main loop
   if(prev_calculated==0) // check for the first start of the indicator
      first=MAPeriod-1+begin; // start index for all the bars
   else first=prev_calculated-1; // start index for the new bars

   //---- main loop of the calculation
   for(bar = first; bar < rates_total; bar++)
    {    
      Sum=0.0;
      //---- summation loop for the current bar averaging
      for(start=0;start<MAPeriod;start++)
         Sum+=price[bar-start]; // It's equal to: Sum = Sum + price[bar - iii];
         
      //---- calculate averaged value
      SMA=Sum/MAPeriod;

      //---- set the element of the indicator buffer with the value of SMA we have calculated
      ExtLineBuffer[bar]=SMA;
    }

What I don't know how to do is to dynamically fill an array, or calculate in a loop, the moving average values firstly according to the initial moving average period. Then the same is calculated forward into the future data. This future data I can obtain by increasing or decreasing the price by a constant value after every minute candle. This should happen dynamically until the price closes on the other side of the moving average. That's where I should get the signal foe the limit order.

If anyone can help me figure out how to fill such an array with indices to the future that would be really helpful. I will take care of other things such as redrawing the extrapolation once the value of the current candle changes(spikes or crashes).

The purpose of this is the ability to notify me of potential spike or crash areas and I would use them to minimize missing trades and reduce risk. As the current systems requires me to buffer in some pips so that I don't miss it during market execution. 

I'm sorry I am not that good in English.

Thanks in advance. 

 
Kevin Onsongo: I need to predict future values of moving average

That's easy: just predict future market values.

 
Try MA with different periods, you might find what you need.
Good luck.