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( |
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
|
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.
Ok, great!!
Thanks for your help!
P.S. : sorry, I've not caught that
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
HI,
Do you know when the ticket will be resolved ?
Thanks for the help,
#include <MovingAverages.mqh> SimpleMa(value_RSI,0,10);
Cheers!
- Do you really expect that they are still waiting for a solution after five years?
- Or just write your own. Not tested, not compiled, just typed.
template<typename T> T mean(const T& arr[], int iBeg=0, int length=14){ return sum_array(arr, iBeg, iBeg+length) / length; } template<typename T> T sum_array(const T& arr[], int iBeg, int iEnd){ T sum=arr[iBeg]; while(++iBeg < iEnd) sum += arr[iBeg]; return sum; }
Not tested, not compiled, just typed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I need to calculate the average value of some values inside a vector. Let me explain better:
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:
The problem is that it returns an error.
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