Useful features from KimIV - page 34

 
KimIV писал (а) >>

Pointers in MQL4 are tricky. There is no direct support. Someone here on the forum tried to do it with arrays, I think. I can't be more precise. Search for it yourself.

MathRand()

You can change only the first dimension of the array programmatically. The ArrayResize() function. The second, third and fourth dimensions have to be set rigidly.

Well, let's forget about pointers and dynamic arrays too...

Looking forward to the 5th version of the language...

Thanks for the help...



Working with one grid is easy to implement.

Funny thing is, for my idea one network was not enough, and I wanted to make an algorithm for switching between networks, with pointers it's not hard.

But no... ...we'll have to hardcode it.

 

The SetTLineByAngle() function.

This function sets the OBJ_TRENDBYANGLE object of the trend line by the slope angle on 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 - open 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);
}
 

Examples of how to use SetTLineByAngle().

  1. Orange solid beam at 45° angle from the minimum of the 5th bar.
    SetTLineByAngle(Orange, "", Time[5], Low[5], 0, 0, 45, True);
  2. A fan of red dotted rays from the minimum of the 13th bar.
    for (int i=0; i<90; i+=10)
      SetTLineByAngle(Red, "TL"+i, Time[13], Low[13], 0, 0, i, True, STYLE_DOT);

ZY. Attached is a script for testing SetTLineByAngle().

Files:
 

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

Examples of how to use SetArrow().

  • The golden left price mark er at the high of the 9th bar.
    SetArrow(5, Gold, "", Time[9], High[9], 3);

  • Red right price mark at the maximum of the 2nd bar.
    SetArrow(6, Red, "", Time[2], High[2], 3);

  • 3. Blue arrow above the maximum of the 2nd bar.
    SetArrow(242, Blue, "", Time[2], High[2]+50*Point, 2);
    

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

Files:
 
Thank you very much for what you do, do you mind if I collect the features from this thread, and post them on my website, in a separate section with a link to the forum, and to your site
 

In general, it would be cool to have a "Table of Contents" on the first page of this post. A table with a list of functions, descriptions and links to pages. Or keep one updated archive on the first page, and the descriptions can be found on the other pages.

So, if xrust will make his suggestion, it would be good to repeat it here. For the sake of systematization of the hard-earned :))

 
xrust писал (а) >>
...do you mind if I collect features from this thread, and post them on my website, in a separate section with a link to the forum, and to your site

No, I won't...

 
xrust писал (а) >>
Thank you very much for what you're doing, would you mind if I collect the functions from this branch, and post them on my site, in a separate section with a reference to the forum and your site

Create an "inluder" file (mqh) (probably 2 - "trade" and "other"), agree on its name and force the "developers" to include it in the distribution. So that everyone in each EA does not have to reinvent the wheel.

:)

 
Thank you again, I'm just a little lazy, I want to collect everything at hand. Another question, would you mind if I use the same syntax and variable names in my functions as you do, to standardize them, so to speak.
Reason: