Useful features from KimIV - page 35

 
xrust писал (а) >>
Another question, would you mind if I used your syntax and variable names in my functions, so to speak, to standardize them.

Do what you think is right.

 

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

Examples of how to use SetLabel().

  • Three blue text labels in upper left corner, font 9.
    SetLabel("Label1", "Текстовая метка", Blue, 5, 15);
    SetLabel("Label2", "Ещё одна текстовая метка", Blue, 5, 30);
    SetLabel("Label3", "Параметр cr=0", Blue, 5, 45);

  • Three purple text labels in the upper right corner, font 12.
    SetLabel("Label1", "Текстовая метка", Magenta, 5, 15, 1, 12);
    SetLabel("Label2", "Ещё одна текстовая метка", Magenta, 5, 30, 1, 12);
    SetLabel("Label3", "Параметр cr=1", Magenta, 5, 45, 1, 12);

  • Three green text labels in lower right corner, font 12.
    SetLabel("Label1", "Текстовая метка", Green, 5, 15, 3, 12);
    SetLabel("Label2", "Ещё одна текстовая метка", Green, 5, 30, 3, 12);
    SetLabel("Label3", "Параметр cr=3", Green, 5, 45, 3, 12);


ZS. Attached is a script to test the SetLabel() function.

Files:
 
SergNF писал (а) >>

Create an "inluder" file (mqh) (probably 2 - "trade" and "other"), agree on its name and force the "developers" to include it in the distribution.

You can't kill the idea, it's been a long time coming for consolidation. My dream as a non-professional is to leave the ordinary user only decision making, freeing him from software intricacies.

Igor's developments (stunning in their consistency and detail) came as close to this as possible. Moreover, the author not only programs, but constantly keeps his

Advisors in real trading, which increases the practical value of the code.

It would be interesting to learn Igor's opinion about the possibility of mqh-framing of his developments and about advantages and disadvantages of such an implementation.

 
granit77 писал (а) >>
I would like to know Igor's opinion about the possibility of mqh-design of his developments, advantages and disadvantages of such an implementation.

About the possibilities...

I've had the MQH files done for a while now... I'm not posting them yet... I've got an ace up my sleeve... The final chord will be... I'll post all the features and sum it up by posting the mqh-files.

The pros and cons...

MQH-files are convenient. You can use them in different Expert Advisors. The code of a specific EA is significantly reduced. Only the bare logic and some other things are left, and all the gadgets and wrappings are outside.

However, I rarely use mqh-files, in general, only one. It's stdlib.mqh. I've copied all of the necessary functions into Expert Advisor's file. It's more convenient to me. I got into this habit when I was working a lot on orders and often forgot to send one or another mqh-file to my client. In addition, I want to copy one EA file to different terminal folders instead of dragging the whole heap of inludes after it.

 
It's not just a delight! It is delightful! The day is not far off when a distribution without such a library will be considered incomplete.
 

Maybe you have a script in useful functions that could do the opening of orders described in the article http://www.kroufr.ru/content/view/1027/124/.

If not, advise me where to find one. .

 

The CrossPointOfLines() function.

This function calculates the coordinates of the intersection point of two lines. Each line is defined by a pair of coordinates of its points. 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 sought 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;
  }
}
 

An example of using the CrossPointOfLines() function.

As an example of using the CrossPointOfLines() function, I traditionally offer my script (see attachment). For the script to work properly, you need to draw two intersecting lines on the current chart of any of the following types: vertical, horizontal or trend. Then the script should be attached to the chart. The script will result in marking the left price at the intersection point of the two lines.

SZY. Attached is a script to test the CrossPointOfLines() function.

 

The SetRegression() function.

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

  • cl - Color of the object. Required 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);
}