Sigma

 

Is there any function in mql4 to get sigma (summation)? I checked in Math functions and could not find it. Thanks in advance

 

 
+ and a loop.
 
Alain Verleyen:
+ and a loop.
ok then as i though there no specific function for that i will do what you said thank you so much.
 
Damian Mateusz Dziadosz:
ok then as i though there no specific function for that i will do what you said thank you so much.

Hi,

you could use the following code:

 

double ArraySum(const double &v[],int _count=WHOLE_ARRAY) {

  double s=0.;

  if (_count==WHOLE_ARRAY) _count=ArraySize(v);

  for (int i=0; i<_count; i++) {

    s += v[i];

  }

  return s;

}


int ArraySum(const int &v[],int _count=WHOLE_ARRAY) {

  int s=0.;

  if (_count==WHOLE_ARRAY) _count=ArraySize(v);

  for (int i=0; i<_count; i++) {

    s += v[i];

  }

  return s;


 

It implements a function ArraySum(array,count) that returns the summation of either the whole given array, if you don't specify the "count" argument, or of its first "count" elements. The two implementations (overloading) are needed to allow to give both a int and a double array.