Only "Useful features from KimIV". - page 6

 

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);
  }
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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);
}
 

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);
}

The ArrayAvGeom() function.

This function returns the geometric mean of the array items.

  • x - An array of elements of the double type.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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);
}
 

The SetHLine() function.

This function sets the OBJ_HLINE horizontal line object on the current chart.

  • cl - Color of the OBJ_HLINE horizontal line object. Required parameter.
  • nm - object name. If the default value "" is passed, the open time of the current bar is used as the object name.
  • p1 - price level of the object. Default value - 0 - current Bid price.
  • st - Line style. Admissible values are STYLE_SOLID (by default) - solid line, STYLE_DASH - dashed line, STYLE_DOT - dashed line, STYLE_DASHDOT - dashed line, STYLE_DASHDOT - dashed line with double dots.
  • wd - Line thickness. Default value is 0.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 30.03.2008                                                     |
//|  Описание : Установка объекта OBJ_HLINE горизонтальная линия               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    p1 - ценовой уровень            (0  - Bid)                              |
//|    st - стиль линии                (0  - простая линия)                    |
//|    wd - ширина линии               (0  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetHLine(color cl, string nm="", double p1=0, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_HLINE, 0, 0,0);
  ObjectSet(nm, OBJPROP_PRICE1, p1);
  ObjectSet(nm, OBJPROP_COLOR , cl);
  ObjectSet(nm, OBJPROP_STYLE , st);
  ObjectSet(nm, OBJPROP_WIDTH , wd);
}

The SetVLine() function.

This function sets the OBJ_VLINE object vertical line on the current chart.

  • cl - Color of the VERTICAL LINE object. Obligatory parameter.
  • nm - object name. When the default value is passed - "", the open time of the current bar is used as the object name.
  • t1 - Object setting time. Default value - 0 - current bar open time.
  • st - Line style. Valid values are STYLE_SOLID (default), STYLE_DASH, STYLE_DOT, STYLE_DASHDOT.
  • wd - Line width. Default value is 1.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 02.07.2008                                                     |
//|  Описание : Установка объекта OBJ_VLINE вертикальная линия                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    t1 - время                      (0  - время открытия текущего бара)     |
//|    st - стиль линии                (0  - простая линия)                    |
//|    wd - ширина линии               (1  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetVLine(color cl, string nm="", datetime t1=0, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[0];
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_VLINE, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1, t1);
  ObjectSet(nm, OBJPROP_COLOR, cl);
  ObjectSet(nm, OBJPROP_STYLE, st);
  ObjectSet(nm, OBJPROP_WIDTH, wd);
}
 

The SetTLine() function.

This function sets the OBJ_TREND trendline object on the current chart.

  • cl - Color of the TREND LINE object. It is a mandatory parameter.
  • nm - Object name. When the default value is passed - "", the open time of the current bar is used as the name.
  • t1 - First coordinate of object setting time. Default value - 0 - opening time of the tenth bar.
  • p1 - First coordinate of object setting price. Default value - 0 - minimum of the tenth bar.
  • t2 - Second coordinate of object setting time. Default value - 0 - open time of the current bar.
  • p2 - Second coordinate of object setting price. Default value - 0 - current bar low.
  • ry - Flag of the BLUE property. The default value is False.
  • st - Line style. Valid values are STYLE_SOLID (default), STYLE_DASH, STYLE_DOT, STYLE_DASHDOT.
  • wd - Line width. Default value is 1.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_TREND трендовая линия                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               (  ""  - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10]                       |
//|    p1 - ценовой уровень            (  0   - Low[10])                       |
//|    t2 - время открытия бара        (  0   - текущий бар)                   |
//|    p2 - ценовой уровень            (  0   - Bid)                           |
//|    ry - луч                        (False - по умолчанию)                  |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetTLine(color cl, string nm="",
              datetime t1=0, double p1=0, datetime t2=0, double p2=0,
              bool ry=False, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[10];
  if (p1<=0) p1=Low[10];
  if (t2<=0) t2=Time[0];
  if (p2<=0) p2=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_TREND, 0, 0,0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1 , t1);
  ObjectSet(nm, OBJPROP_PRICE1, p1);
  ObjectSet(nm, OBJPROP_TIME2 , t2);
  ObjectSet(nm, OBJPROP_PRICE2, p2);
  ObjectSet(nm, OBJPROP_COLOR , cl);
  ObjectSet(nm, OBJPROP_RAY   , ry);
  ObjectSet(nm, OBJPROP_STYLE , st);
  ObjectSet(nm, OBJPROP_WIDTH , wd);
}

Function SetTLineByAngle().

This function sets the OBJ_TRENDBYANGLE object by the slope angle in the current chart.

  • cl - Color of the TRENDBYANGLE object. Required parameter.
  • nm - Object name. When the default value is passed - "", the open time of the current bar is used as the name.
  • t1 - First coordinate of object setting time. Default value - 0 - opening time of the tenth bar.
  • p1 - First coordinate of object setting price. Default value - 0 - minimum of the tenth bar.
  • t2 - Second coordinate of object setting time. Default value - 0 - open time of the current bar.
  • p2 - Second coordinate of object setting price. This parameter is a kind of switch. Its non-zero value equates this function to SetTLine(), i.e. a trend line will be drawn using the time/price coordinate pair, while the value of the slope angle of the trend line will be ignored. Default value - 0 - trend line construction by slope angle.
  • an - Slope angle in degrees. Default value - 0 - Horizontal line.
  • ry - Flag of the BOW property. The default value is False.
  • st - Line style. Valid values are STYLE_SOLID (default), STYLE_DASH, STYLE_DOT, STYLE_DASHDOT.
  • wd - Line width. Default value is 1.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_TRENDBYANGLE трендовая линия по углу     |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               (  ""  - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10]                       |
//|    p1 - ценовой уровень            (  0   - Low[10])                       |
//|    t2 - время открытия бара        (  0   - время открытия текущего бара)  |
//|    p2 - ценовой уровень            (  0   - по углу)                       |
//|    an - угол                       (  0   - по умолчанию)                  |
//|    ry - луч                        (False - не луч)                        |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetTLineByAngle(color cl, string nm="",
              datetime t1=0, double p1=0, datetime t2=0, double p2=0,
              double an=0, bool ry=False, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[10];
  if (p1<=0) p1=Low[10];
  if (t2<=0) t2=Time[0];
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_TRENDBYANGLE, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1 , t1);
  ObjectSet(nm, OBJPROP_PRICE1, p1);
  ObjectSet(nm, OBJPROP_TIME2 , t2);
  if (p2>0) ObjectSet(nm, OBJPROP_PRICE2, p2);
  else ObjectSet(nm, OBJPROP_ANGLE, an);
  ObjectSet(nm, OBJPROP_COLOR, cl);
  ObjectSet(nm, OBJPROP_RAY  , ry);
  ObjectSet(nm, OBJPROP_STYLE, st);
  ObjectSet(nm, OBJPROP_WIDTH, wd);
}
 

The SetArrow() function.

This function sets the OBJ_ARROW object icon to the current chart.

  • cd - icon code. Required parameter.
  • cl - Color of the icon. Required parameter.
  • nm - Name of the object. If default value is transferred - "" the open time of current bar is used as a name.
  • t1 - First coordinate of object's setting time. Default value - 0 - current bar open time.
  • p1 - First coordinate of object setting price. Default value - 0 - current Bid price.
  • sz - Size of the icon. Default value - 0.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка значка на графике, объекта OBJ_ARROW.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cd - код значка                                                         |
//|    cl - цвет значка                                                        |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    t1 - время открытия бара        (0  - текущий бар)                      |
//|    p1 - ценовой уровень            (0  - Bid)                              |
//|    sz - размер значка              (0  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetArrow(int cd, color cl,
              string nm="", datetime t1=0, double p1=0, int sz=0) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[0];
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_ARROW, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1    , t1);
  ObjectSet(nm, OBJPROP_PRICE1   , p1);
  ObjectSet(nm, OBJPROP_ARROWCODE, cd);
  ObjectSet(nm, OBJPROP_COLOR    , cl);
  ObjectSet(nm, OBJPROP_WIDTH    , sz);
}

SetLabel() function.

This function sets the OBJ_LABEL text label object in the current chart.

  • nm - name of the object. Required parameter.
  • tx - Text. Required parameter.
  • cl - Marker colour. Required parameter.
  • xd - X coordinate in pixels relative to the reference angle. Required parameter.
  • yd - Y coordinate in pixels relative to the datum angle. Mandatory parameter.
  • cr - Reference angle number. Valid values: 0 top-left, 1 top-right, 2 bottom-left, 3 bottom-right. Default value is 0.
  • fs - Font size. Default value is 9.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка текстовой метки, объект OBJ_LABEL.                   |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    nm - наименование объекта                                               |
//|    tx - текст                                                              |
//|    cl - цвет метки                                                         |
//|    xd - координата X в пикселах                                            |
//|    yd - координата Y в пикселах                                            |
//|    cr - номер угла привязки        (0 - левый верхний,                     |
//|                                     1 - правый верхний,                    |
//|                                     2 - левый нижний,                      |
//|                                     3 - правый нижний )                    |
//|    fs - размер шрифта              (9 - по умолчанию  )                    |
//+----------------------------------------------------------------------------+
void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=0, int fs=9) {
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0);
  ObjectSetText(nm, tx, fs);
  ObjectSet(nm, OBJPROP_COLOR    , cl);
  ObjectSet(nm, OBJPROP_XDISTANCE, xd);
  ObjectSet(nm, OBJPROP_YDISTANCE, yd);
  ObjectSet(nm, OBJPROP_CORNER   , cr);
  ObjectSet(nm, OBJPROP_FONTSIZE , fs);
}
 

The CrossPointOfLines() function.

This function calculates the coordinates of the intersection point of two lines. Each line is defined by a pair of its point coordinates. Three arrays are passed to the function as parameters:

  • x - Abscissa array. It should contain four elements: x[0], x[1] - the abscissa of the first line, x[2], x[3] - the abscissa of the second line.
  • y - Array of ordinates. Should contain four elements: y[0], y[1] - the ordinates of the first line, y[0], y[1] - the ordinates of the second line.
  • t - Array of coordinates of the intersection point of the two lines. After the normal execution of the function this array will contain two elements: t[0] is the abscissa of the point of intersection of the two lines and t[1] is the ordinate of the same point.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Вычисляет координаты точки пересечения двух прямых.            |
//|             Каждая прямая задаётся парой координат своих точек.            |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив абсцисс              x[0], x[1] - первая прямая              |
//|                                    x[2], x[3] - вторая прямая              |
//|    y - массив ординат              y[0], y[1] - первая прямая              |
//|                                    y[0], y[1] - вторая прямая              |
//|    t - массив искомых координат    t[0]       - абсцисса                   |
//|                                    t[1]       - ордината                   |
//+----------------------------------------------------------------------------+
void CrossPointOfLines(double& x[], double& y[], double& t[]) {
  double z=(y[3]-y[2])*(x[1]-x[0])-(y[1]-y[0])*(x[3]-x[2]);
  ArrayResize(t, 2);
  ArrayInitialize(t, 0.0);

  if (z==0) Print("CrossPointOfLines(): Не удалось найти точку пересечения!");
  else {
    double xy1=x[1]*y[0]-x[0]*y[1];
    double xy2=x[3]*y[2]-x[2]*y[3];
    t[0]=NormalizeDouble((xy1*(x[3]-x[2])-xy2*(x[1]-x[0]))/z, 0);
    t[1]=(xy1*(y[3]-y[2])-xy2*(y[1]-y[0]))/z;
  }
}

Function SetRegression().

This function sets the OBJ_REGRESSION object of the linear regression channel on the current chart.

  • cl - Color of the object. It is a mandatory parameter.
  • nm - Name of the object. When the default value is passed - "", the opening time of the current bar is used as the name.
  • t1 - First coordinate of object setting time. Default value - 0 - opening time of the tenth bar.
  • t2 - Second coordinate of object setting time. The default value is 0 - the open time of the current bar.
  • ry - Flag of the BOW property. Default value is False.
  • st - Line style. Valid values are STYLE_SOLID (default), STYLE_DASH, STYLE_DOT, STYLE_DASHDOT.
  • wd - Line width. Default value is 1.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_REGRESSION канал линейной регрессии.     |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               ( ""   - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10])                      |
//|    t2 - время открытия бара        (  0   - Time[0])                       |
//|    ry - луч                        (False - по умолчанию)                  |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetRegression(color cl, string nm="", datetime t1=0, datetime t2=0,
                    bool ry=False, int st=STYLE_SOLID, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[10];
  if (t2<=0) t2=Time[0];
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_REGRESSION, 0, 0,0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1, t1);
  ObjectSet(nm, OBJPROP_TIME2, t2);
  ObjectSet(nm, OBJPROP_COLOR, cl);
  ObjectSet(nm, OBJPROP_RAY  , ry);
  ObjectSet(nm, OBJPROP_STYLE, st);
  ObjectSet(nm, OBJPROP_WIDTH, wd);
}
 

The EquationDirect() function.

The equation of a straight line. This function calculates the value of the ordinate Y for the abscissa X at the intersection with a line drawn through two arbitrary points on the graph. The function takes the following mandatory parameters:

  • x1, y1 - Coordinates of the first point.
  • x2, y2 - Coordinates of the second point.
  • x - Value, the abscissa for which the Y ordinate is to be calculated.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Уравнение прямой.                                              |
//|             Вычисляет значение Y для X в точке пересечения с прямой.       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x1,y1 - координаты первой точки,                                        |
//|    x2,y2 - координаты второй точки,                                        |
//|    x     - значение, для которого вычислить Y                              |
//+----------------------------------------------------------------------------+
double EquationDirect(double x1, double y1, double x2, double y2, double x) {
  if (x2==x1) return(y1);
  return((y2-y1)/(x2-x1)*(x-x1)+y1);
}

GetArrowInterval() function.

I wrote this function to improve the convenience of developing signal indicators, i.e. those indicators that give clear buy or sell signals. The signal of such indicator I usually make as a down arrow above the Khai of a bar or as an up arrow below the low of the corresponding bar. The value of "under" and "over" was usually a few points, so the arrow would not "run over" the bar. It wasn't much of a problem in case of a single timeframe indicator designed for one hour bars only, for example. For each timeframe I had different values "under" and "over". However, for multiframe indicators I had to use the GetArrowInterval() function:

//+------------------------------------------------------------------+
//| Возвращает интервал установки сигнальных указателей              |
//+------------------------------------------------------------------+
int GetArrowInterval() {
  int p = Period();

  switch (p) {
    case 1:     return(4);
    case 5:     return(5);
    case 15:    return(6);
    case 30:    return(8);
    case 60:    return(10);
    case 240:   return(20);
    case 1440:  return(40);
    case 10080: return(80);
    case 43200: return(150);
  }
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//+----------------------------------------------------------------------------+
//|  Описание : Возвращает интервал установки сигнальных указателей            |
//|  Параметры:                                                                |
//|    pr - процент относительно ценового размера окна                         |
//+----------------------------------------------------------------------------+
int GetArrowInterval(int pr=7) {
  if (pr<=0) pr=7;
  return((WindowPriceMax()-WindowPriceMin())/100*pr/Point);
}
 

Function FindNearFractal().

This function searches for the nearest fractal and returns its price level. The function accepts the following optional parameters:

  • sy - Name of the instrument. "" or NULL - current symbol. Default value is NULL.
  • tf - Timeframe. Default value 0 - current symbol.
  • mode - Fractal type. MODE_LOWER and MODE_UPPER are allowed. Default value is MODE_LOWER.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Поиск ближайшего фрактала. Возвращает ценовой уровень.         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy   - наименование инструмента      ("" или NULL - текущий символ)     |
//|    tf   - таймфрейм                     (    0       - текущий ТФ)         |
//|    mode - тип фрактала                  (MODE_LOWER|MODE_UPPER)            |
//+----------------------------------------------------------------------------+
double FindNearFractal(string sy="0", int tf=0, int mode=MODE_LOWER) {
  if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int    d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;

  for (s=2; s<100; s++) {
    f=iFractals(sy, tf, mode, s);
    if (f!=0) return(NormalizeDouble(f, d));
  }
  Print("FindNearFractal(): Фрактал не найден");
  return(0);
}

GetExtremumZZBar() function.

This function searches for an extremum of the standard custom ZigZag indicator and returns the bar number. The function accepts the following optional parameters:

  • sy - Name of the instrument. "" or NULL - the current symbol. Default value is NULL.
  • tf - Timeframe. The default value is 0 - the current timeframe.
  • ne - Extreme number. 0 - last, 1 - previous, 2 - previous, etc.
  • dp, dv, bs - ZigZaga parameters: ExtDepth, ExtDeviation, ExtBackstep respectively.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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);
}
 

GetExtremumZZZPrice() function.

This function searches for an extremum of the standard custom ZigZag indicator and returns its price level. The function accepts the following optional parameters:

  • sy - Name of the instrument. "" or NULL - current symbol. Default value is NULL.
  • tf - Timeframe. Default value 0 - current symbol.
  • ne - Extreme number. 0 - last, 1 - previous, 2 - previous, etc.
  • dp, dv, bs - ZigZaga parameters: ExtDepth, ExtDeviation, ExtBackstep.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает экстремум ЗигЗага по его номеру.                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    tf - таймфрейм                  (      0     - текущий ТФ)              |
//|    ne - номер экстремума           (      0     - последний)               |
//|    dp - ExtDepth                                                           |
//|    dv - ExtDeviation                                                       |
//|    bs - ExtBackstep                                                        |
//+----------------------------------------------------------------------------+
double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=1; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(zz);
    }
  }
  Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 13.08.2008                                                     |
//|  Описание : Возвращает номер бара фрактала по его номеру.                  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента        ("" или NULL - текущий символ)     |
//|    tf - таймфрейм                       (    0       - текущий ТФ)         |
//|    nf - номер фрактала                  (    0       - последний)          |
//+----------------------------------------------------------------------------+
int GetFractalBar(string sy="0", int tf=0, int nf=0) {
  if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int    i, k=iBars(sy, tf), kf;

  for (i=2; i<k; i++) {
    f=iFractals(sy, tf, MODE_LOWER, i);
    if (f!=0) {
      kf++;
      if (kf>nf) return(i);
    }
    f=iFractals(sy, tf, MODE_UPPER, i);
    if (f!=0) {
      kf++;
      if (kf>nf) return(i);
    }
  }
  Print("GetFractalBar(): Фрактал не найден");
  return(-1);
}
 

GetNearestDownFractal() function.

This function searches for the nearest bottom fractal and returns its price level. The peculiarity of this function is the possibility to set an arbitrary formula for the fractal. The standard, generally accepted fractal formula is 2-2. It means 2 bars on the left and 2 bars on the right. With this function, you can perform even very exotic fractals, such as 8-2 (8 bars on the left and 2 bars on the right) or 5-3 (5 bars on the left and 3 bars on the right) and so on. The function accepts the following optional parameters:

  • sy - Name of instrument. "" or NULL - current symbol. Default value is NULL.
  • tf - Timeframe. Default value 0 - current symbol.
  • nl - Number of bars on the left. Default value is 2.
  • nr - Number of bars on the right. Default value - 2.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает ценовой уровень ближайшего нижнего фрактала         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//|    tf - таймфрейм                  (    0       - текущий таймфрейм)       |
//|    nl - количество баров слева                                             |
//|    nr - количество баров справа                                            |
//+----------------------------------------------------------------------------+
double GetNearestDownFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
  bool f;
  int  fb, i, nb=-1;

  if (sy=="" || sy=="0") sy=Symbol();
  if (nl<1) nl=1;
  if (nr<1) nr=1;

  fb=nr;
  while (nb<0) {
    fb++;
    f=True;
    for (i=fb; i>fb-nr; i--) {
      if (iLow(sy, tf, i)>iLow(sy, tf, i-1)) { f=False; break; }
    }
    if (f) {
      for (i=fb; i<fb+nl; i++) {
        if (iLow(sy, tf, i)>iLow(sy, tf, i+1)) { f=False; break; }
      }
      if (f) { nb=fb; break; }
    }
  }

  return(iLow(sy, tf, nb));
}

GetNearestUpFractal() function.

This function searches for the nearest upward fractal and returns its price level. The peculiarity of this function is the possibility to set an arbitrary formula for the fractal. The standard, generally accepted fractal formula is 2-2. It means 2 bars on the left and 2 bars on the right. With this function, you can perform even very exotic fractals, such as 8-2 (8 bars on the left and 2 bars on the right) or 5-3 (5 bars on the left and 3 bars on the right) and so on. The function accepts the following optional parameters:

  • sy - Name of instrument. "" or NULL - current symbol. Default value is NULL.
  • tf - Timeframe. Default value 0 - current symbol.
  • nl - Number of bars on the left. Default value is 2.
  • nr - Number of bars on the right. Default value - 2.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает ближайший верхний фрактал                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL - текущий символ)                 |
//|    tf - таймфрейм                  ( 0 - текущий таймфрейм)                |
//|    nl - количество баров слева                                             |
//|    nr - количество баров справа                                            |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
  bool f;
  int  fb, i, nb=-1;

  if (sy=="" || sy=="0") sy=Symbol();
  if (nl<1) nl=1;
  if (nr<1) nr=1;

  fb=nr;
  while (nb<0) {
    fb++;
    f=True;
    for (i=fb; i>fb-nr; i--) {
      if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
    }
    if (f) {
      for (i=fb; i<fb+nl; i++) {
        if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
      }
      if (f) { nb=fb; break; }
    }
  }

  return(iHigh(sy, tf, nb));
}
Reason: