Download MetaTrader 5

Moving Average in a separate window

To add comments, please log in or register
mk731
31
mk731  

Hey,

Using MQL4:

I'm trying to get moving average in separate window.

But the values are all wrong, it won't match up one to one, it seems random.

Can you please help me create moving averages in a separate window?

Files:
whroeder1
17085
whroeder1  
  1. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?) instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. (The moderators will likely move this thread there soon.

  2. Your buffers and loop is non-series but iMA is as-series. Do it as-series, counting down to zero (current.) Or convert your non-series i to as-series: Bars-1-i
              How to do your lookbacks correctly.

  3.  MAGradBuff[i]=iMA(NULL,0,MAL,0,MODE_SMA,close[i],i);
    double  iMA(
       string       symbol,           // symbol
       int          timeframe,        // timeframe
       int          ma_period,        // MA averaging period
       int          ma_shift,         // MA shift
       int          ma_method,        // averaging method
       int          applied_price,    // applied price
       int          shift             // shift
       );
              iMA - Technical Indicators - MQL4 Reference
    What do you think the applied_price you are using is?
mk731
31
mk731  

sorry i'll post in mql4

whroeder1
17085
whroeder1  
Don't double post, the moderators will move it.
Mladen Rakic
72093
Mladen Rakic  
mk731:

Hey,

Using MQL4:

I'm trying to get moving average in separate window.

But the values are all wrong, it won't match up one to one, it seems random.

Can you please help me create moving averages in a separate window?

Do it like this :

int OnCalculate (const int       rates_total,
                 const int       prev_calculated,
                 const datetime& time[],
                 const double&   open[],
                 const double&   high[],
                 const double&   low[],
                 const double&   close[],
                 const long&     tick_volume[],
                 const long&     volume[],
                 const int&      spread[] )
{
   int counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
            int limit=MathMin(rates_total-counted_bars,rates_total-1); 
            for(int i=limit; i>=0; i--) MAGradBuff[i]=iMA(NULL,0,MAL,0,MODE_SMA,PRICE_CLOSE,i);
   return(rates_total);
}            
To add comments, please log in or register