Moving average of a custom indicator?

 

Dear fellow coders,

I'm having serious trouble with generating a simple moving average over a custom indicator. To be more concrete it's the 'VHF' indicator which can be found by following the link: 'SVOS Multi-Indicator EA'

If you have any suggestions/recommendations or a hint as to where I should start, I would be grateful.

I wonder if it is possible to use the 'iMA' function of the MQL4 or this is complete non-sense.

I'm looking forward to hearing from you.

Best regards

Garnak

 

If you're working with an indicator try move the VHF data to an array, and then use iMAonArray.

Just be aware that iMAonArray has some problems if it is used in an EA.

A possible solution in an EA may be to simulate SMA by adding N VHF samples, then divide sum by N.

 

First of all - Thank you for the prompt and useable reply,

I feel that making an addition to the original custom indicator by adding N variables suits me better at present. It's more of a here and now solution, than a major change I'm looking for.

If anyone else has suggestions or comments - please hit me (or rather this thread).

Best regards

 

You may want to play a little with this filter code. The filter has a slight feedback (redrawing), but that can be eliminated by

using a dedicated summing variable here: MO[Pos4] = MO[Pos4] + MO2[Pos4+i2]/SMAfilter;

//----------------- Smoothing --------------------------------------      
      int   i=Pos4;
      int   SMAfilter=10;//Filter Average Bars
      int   i2=0;
      while(Pos4>=0)
      {
         //-------- SMA filter for Bar Pos4 --------------
         MO[Pos4] = 0;
         while(i2<=SMAfilter) 
         {
         MO[Pos4] = MO[Pos4] + MO2[Pos4+i2]/SMAfilter;
         i2++;
         }         
         i2=0;
         
         //-----------------------------------------------
 
      Pos4--;
      }
//------------------------------------------------------------------ 
Reason: