Useful features from KimIV - page 28

 

The ArrayMax() function.

This function returns the value of the maximum element of the array.

  • x is an array of elements of type double, in which the maximum value of the element is searched for.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 17.05.2008                                                     |
//|  Описание : Возвращает значение максимального элемента массива.            |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//+----------------------------------------------------------------------------+
double ArrayMax(double& x[]) {
  if (ArraySize(x)>0) return(x[ArrayMaximum(x)]);
  else {
    Print("ArrayMax(): Массив пуст!");
    return(0);
  }
}
P.S. Attached is a script to test ArrayMax() function.
Files:
 

The ArrayMin() function.

This function returns the value of the minimum element of the array.

  • x - An array of elements of type double, in which the minimum value of the element is searched for.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 17.05.2008                                                     |
//|  Описание : Возвращает значение минимального элемента массива.             |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//+----------------------------------------------------------------------------+
double ArrayMin(double& x[]) {
  if (ArraySize(x)>0) return(x[ArrayMinimum(x)]);
  else {
    Print("ArrayMin(): Массив пуст!");
    return(0);
  }
}
ZS. Attached is a script to test ArrayMin() function.
Files:
 

Hello, found a couple of your ZigZag functions on the forum. This is exactly what I need. I decided to check the functionality of these functions, so I made an Expert Advisor that just calls this function in the comment. ZigZag bar number = so-and-so. The problem is that the function only shows the bar number of the zigzag if it is not on zero bar. If the zigzag is on a zero bar, it shows the bar of the previous zigzag. And I need it to show at zero bar. In other words, I want to know when the new zigzag has appeared.

The code of the Expert Advisor is given below:

int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
GetExtremumZZBar ();
 Comment("бар зигзага = ", GetExtremumZZBar());         //Просто проверяю работоспособность функции
//----
   return(0);
  }
//+------------------------------------------------------------------+
int GetExtremumZZBar(string sym="EURUSD", int tf=0, int ne=0, int dp=12, int dv=5, int bc=3) {
  if (sym=="") sym=Symbol();
  double zz;
  int    i, k=iBars(sym, tf), ke=0;
 
  for (i=1; i<k; i++) {
    zz=iCustom(sym, tf, "ZigZag", dp, dv, bc, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(i);
    }
  }
  Print("GetExtremumZZBar(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}
 
Climber писал (а) >>

function shows the bar number of the zigzag only if it is not on zero bar.
If the zigzag is on zero bar, it shows the bar of the previous zigzag.
And I need it to show at zero bar. In other words, I want to know when a new zigzag has appeared.

ok... corrected for zero bar

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает номер бара экстремума ЗигЗага по его номеру.        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    tf - таймфрейм                  (      0     - текущий ТФ)              |
//|    ne - номер экстремума           (      0     - последний)               |
//|    dp - ExtDepth                                                           |
//|    dv - ExtDeviation                                                       |
//|    bs - ExtBackstep                                                        |
//+----------------------------------------------------------------------------+
int GetExtremumZZBar(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bc=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=0; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bc, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(i);
    }
  }
  Print("GetExtremumZZBar(): Экстремум ЗигЗага номер ",ne," не найден");
  return(-1);
}
 
TheXpert писал (а) >>

I apologise for my post to the author, I wrote in vain, as I won't be using this code anyway, as I have my own libc with everything I need. And because for such a long time there was no unequivocally negative feedback, it means that the author's code satisfies. Just couldn't stand it :), sorry.

There are a lot of clever people, but clever and kind people are few. You, on the other hand, don't put out your library, even though you think you code better, while Igor puts out for free almost all of his work.

 
khorosh писал (а) >>

There are many smart people, but few smart and kind ones. You don't put out your library, even though you think you code better, while Igor puts out almost all of his work for free.

I've already written why. Because my code is not completely universal. If I can find something to post, I'll do it for sure

 

The ArrayAvg() function.

This function returns the average arithmetic of the array elements.

  • x - An array of elements of type double.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 16.05.2008                                                     |
//|  Описание : Возвращает среднее аримфетическое элементов массива.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//+----------------------------------------------------------------------------+
double ArrayAvg(double& x[]) {
  double s=0;
  int    i, k=ArraySize(x);

  for (i=0; i<k; i++) s+=x[i];
  if (k>0) s/=k; else Print("ArrayAvg(): Массив пуст!");

  return(s);
}
P.S. Attached is a script to test ArrayAvg() function.
Files:
 
KimIV писал (а) >>

ok... corrected for the zero bar.

Thank you very much. Something with the internet at work, couldn't thank you earlier.

 

The ArrayAvGeom() function.

This function returns the geometric mean of the array elements.

  • x - An array of elements of type double.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 16.06.2008                                                     |
//|  Описание : Возвращает среднее геометрическое элементов массива.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//+----------------------------------------------------------------------------+
double ArrayAvGeom(double& x[]) {
  double s=1, k=ArraySize(x);
  int    i;

  for (i=0; i<k; i++) s*=x[i];
  if (k>0) s=MathPow(s, 1/k); else Print("ArrayAvGeom(): Массив пуст!");

  return(s);
}
ZS. Attached is a script to test ArrayAvGeom() function.
Files:
 
KimIV писал (а) >>

The ArrayAvGeom() function.

This function returns the geometric mean of the array elements.

  • x is an array of elements of type double.
ZS. Attached is a script to test the ArrayAvGeom() function.

Dear KimIV , thanks for the function!

Is it realistic to write the same kind of function to calculate the mode?