Adding a moving average to an indicator?

 

I'm a MQL4 newb, but do have some programming background. I have been trying to make some changes to an existing indicator. The first few changes I made (my first MQL4 effort) worked perfectly, but now I'm trying to add a simple moving average to this indicator, that only has a range from 1-100 and I can never get the SMA to draw in the subwindow. I have some alert statements that look like the values are right, just that nothing draws on screen.


What I have done is open up the movingaverages indicator and cut and paste it's code into the new indicator I am modifying. I changed the ClosingPrice variable to the name of the Buffer that the primary indicator uses for its value. Seems like that should have done it, but it's not working.


Any suggestions?


Here is a snippet of the sma section of the movingaverages.mq4 file:

//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
void sma()
  {
   double sum=0;
   int    i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum+=Close[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Close[pos];
      ExtMapBuffer[pos]=sum/MA_Period;
       sum-=Close[pos+MA_Period-1];
        pos--;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
  }

Where in that function should it actually plot it's point, for a drawn line? I thought it was the line that says:


ExtMapBuffer[pos]=sum/MA_Period;

But as I said, nothing ever writes/draws on the screen except my original indicator and the couple of extra things I added. I have allocated plenty of buffers, so that each drawing item has it's own.


Thanks.

 
You don't have to code anything. Simply drag and drop the Moving Average indicator from the navigator panel to your indicator window. Be sure to select "Previous indicator's data" as the value of the "Apply to" field in the MA settings.
 
bstone:
You don't have to code anything. Simply drag and drop the Moving Average indicator from the navigator panel to your indicator window. Be sure to select "Previous indicator's data" as the value of the "Apply to" field in the MA settings.

Yep, you are right. I looked for that option before I wrote my own. I guess I tried the Moving Average of Oscillator and it didn't have the 'previous indicator's data' option and I couldn't get it to print in the oscillator window, only in the chart window. Thanks for the info.

Reason: