Useful features from KimIV - page 47

 

It's the same for me if you call it like this.

  for (int i=0; i<r; i++)  {
    Y[i]=Close[i+1];
    X[i]=i;
  }
    
  Array_LR(X, Y);
  for (i=0; i<r; i++) {
    SetArrow(170, Blue, "arr"+i+r, Time[i+1], Y[i]);
  }

True, the dots in both variants do not overlay exactly. But this is most likely a peculiarity of SetArrow()

Here is a picture

 
Prival писал (а) >>
True, the points in both variants do not overlay exactly. But this is most likely a feature of SetArrow()

No, this is a feature of the OBJ_ARROW graphical object. It is not anchored by the centre of mass, but by the middle of the upper boundary.

 

The ArrayMo() function.

Returns Modu - the maximum of the distribution density curve. The function accepts the following optional parameters:

  • x - Array of numeric series values.
  • d - The accuracy of the numeric series values, the number of decimal places.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 21.06.2008                                                     |
//|  Описание : Возвращает Моду - максимум кривой плотности распределения.     |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//|    d - точность значений числового ряда, количество знаков после запятой   |
//+----------------------------------------------------------------------------+
double ArrayMo(double& x[], int d=4) {
  double e, s=0;
  double m[][2];             // временный массив:
                             //  столбец 1 - количество значений
                             //  столбец 2 - значения
  int    i, k=ArraySize(x);
  int    n;                  // номер строки временного массива m
  int    r;                  // количество строк во временном массиве m

  if (k>0) {
    for (i=0; i<k; i++) {
      e=NormalizeDouble(x[i], d);
      n=ArraySearchDouble(m, e);
      if (n<0) {
        r=ArrayRange(m, 0);
        ArrayResize(m, r+1);
        m[r][0]++;
        m[r][1]=e;
      } else m[n][0]++;
    }
    ArraySort(m, WHOLE_ARRAY, 0, MODE_DESCEND);
    s=m[0][1];
  } else Print("ArrayMo(): Массив пуст!");

  return(s);
}
 

Example of using the ArrayMo() function.

Determines the most frequently occurring High price level among the last 1000 or so bars of the current chart:

#define R 1000
void start() {
  double a[R];
  for (int i=0; i<R; i++) a[i]=High[i];
  Message(ArrayMo(a, 4));
}
SZY. Attached is a script to test the ArrayMo() function.
Files:
 

The b-Array function library has been published in full and is designed to work with arrays.

 

There is another one, calculation of covariance

//+----------------------------------------------------------------------------+
//|  Автор    : Сергей Привалов aka Prival,  Skype: privalov-sv                |
//+----------------------------------------------------------------------------+
//|  Версия   : 11.09.2008                                                     |
//|  Описание : Рассчет ковариации массива cvar(X,Y)                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    X    - массив значений числового ряда, ось X                            |
//|    Y    - массив значений числового ряда, ось Y                            |
//+----------------------------------------------------------------------------+

double cvar(double &X[], double &Y[])
{
      double mo_X = 0, mo_Y = 0, res = 0;
      int    i,N=ArraySize(X);
     
      if(N>1 && ArraySize(Y)==N)  {
        for( i = 0; i < N; i ++ ) {
            mo_X +=X[i]-X[0];
          mo_Y +=Y[i];
      }
      mo_X /=N;
      mo_Y /=N;
      for( i = 0; i < N; i ++ ) res +=(X[i]-mo_X)*(Y[i]-mo_Y);
      res /=N;
    } else Print("cvar(): Недостаточное количество элементов ряда! N=", N, " или не совпадает размерность");
   return(res);

corrected.

 
Prival писал (а) >>

There is another one, calculation of covariance

add it to the library. Although there are much more arrays (matrices) definitions. But I think we will fill it gradually.

There are a couple of questions:

1. what is mo_XY?

2. In the line of accumulation of MOs by X

mo_X +=X[i]-X[0];
Why take away X[0]?
3. Why should array X be ordered?
 

1. mo_XY can be removed, checked different calculation options. This is left over from bad variant.

2. This algorithm that I cited has minimal chances to get error in calculations if Time[] comes in as X. Multiplication of large numbers gradually causes buildup of error and it will appear. Exactly for this purpose, elimination of possible appearance of this error, X is (additionally) shifted to the origin by subtracting X[0]

3. I was overthinking, maybe I'm out of order. The main thing is that the values typed in X correspond to Y

I will correct it now.

 
mo_X += X[0]; // Forgotten probably .
This is an unnecessary operation. You can double-check it.
 
TheXpert писал (а) >>

I disagree.

It's a good rule of thumb to distrust. Check it in any maths package. We'll post the results. I'll do it in MathCade right now.