use of MathMean function

To add comments, please log in or register
managertop40
132
managertop40  

Hello all,

I need to calculate the average value of some values inside a vector. Let me explain better:

#1 CopyBuffer(funz_RSI,0,0,20,value_RSI)

With the above declaration I have the vector value_RSI composed of 20 values.

I want to calculate the average value with the first 10 value of value_RSI, and then the average value with the last 10 value of value_RSI

So I do:

#2 lastRSI_avg=MathMean(value_RSI,0,10);
#3 preRSI_avg=MathMean(value_RSI,11,20);

The problem is that it returns an error.

#4 lastRSI_avg=MathMean(value_RSI);
#5 preRSI_avg=MathMean(value_RSI);

Without any indication of parameters it works, but it does the average of all the values.


I found there is this definition:

https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/array_stat/mathmean

but I've not understood how it works.

Could someone explain me how to do?


Thanks

Documentation on MQL5: Standard Library / Mathematics / Statistics / Statistical Characteristics / MathMean
Documentation on MQL5: Standard Library / Mathematics / Statistics / Statistical Characteristics / MathMean
  • www.mql5.com
Standard Library / Mathematics / Statistics / Statistical Characteristics / MathMean - Reference on algorithmic/automated trading language for MetaTrader 5
Vladimir Karputov
Moderator
120834
Vladimir Karputov  

Here is the apparent discrepancy between the help and the standard library.

MathMean (MQL5 help):

Calculates the mean (first moment) of array elements. Analog of themean()in R.

double  MathMean(
   const double&  array[],               // array with data
   const int      start=0,               // initial index 
   const int      count=WHOLE_ARRAY      // the number of elements

   );

Parameters

array

[in]  Array with data for calculation of the mean.

start=0

[in]  Initial index for calculation.

count=WHOLE_ARRAY

[in]  The number of elements for calculation.

Return Value

The mean of array elements. In case of error it returnsNaN(not a number).


But the standard library (\MQL5\include\Math\Stat\Math.mqh):

//+------------------------------------------------------------------+
//| Computes the mean value of the values in array[]                 |
//+------------------------------------------------------------------+
double MathMean(const double &array[])
  {
   int size=ArraySize(array);
//--- check data range
   if(size<1)
      return(QNaN); // need at least 1 observation
//--- calculate mean
   double mean=0.0;
   for(int i=0; i<size; i++)
      mean+=array[i];
   mean=mean/size;
//--- return mean
   return(mean);
  }

As you can see in the standard library there are no parameters


   const int      start=0,               // initial index 
   const int      count=WHOLE_ARRAY      // the number of elements



Vladimir Karputov
Moderator
120834
Vladimir Karputov  
Report on ServiceDesk.
managertop40
132
managertop40  
Vladimir Karputov:
Report on ServiceDesk.

So?

I have not understood how to solve my issue. Thanks

Vladimir Karputov
Moderator
120834
Vladimir Karputov  
managertop40 :

So?

I have not understood how to solve my issue. Thanks


I filed a report. We are waiting for a response from the Service Desk.
managertop40
132
managertop40  

Ok, great!!


Thanks for your help!


P.S. : sorry, I've not caught that

managertop40
132
managertop40  

Ok, report the issue!


But if I want to solve it, practically how can I do?


I tried something like this:

double aux[];
for(int i=15;i<20;i++)
     {
      int h=i-15;
      aux[h]=vector_to_avg[i];
     }
double median_vector=MathMedian(aux);

but it doesn't work! It makes crash MetaEditor. Why?


How could I solve?


Thanks

alexandre.durand.spam
628
alexandre.durand.spam  

HI,

Do you know when the ticket will be resolved ?


Thanks for the help,

To add comments, please log in or register