Useful features from KimIV - page 33

 

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

Examples of how to use SetVLine().

  1. Blue solid vertical line on current bar.
    SetVLine(Aqua);
  2. Lilac thick line on the eighth bar.
    SetVLine(Magenta, "", Time[8], STYLE_SOLID, 3);
  3. Grid of dotted lines on bars 14:00.
    for (int i=0; i<7; i++) {
      datetime dt=StrToTime((TimeToStr(TimeCurrent()-i*1440*60, TIME_DATE))+" 14:00");
      int nb=iBarShift(NULL, 0, dt, True);
      SetVLine(Coral, "VLine"+i, Time[nb], STYLE_DOT);
    }

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

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

EXECUTIVE. >> I'M GOING TO.

Show me a picture, let's try to make one.

 
TheXpert писал (а) >>

Show it in the figure, let's try to do it.

A custom function that calculates the areas described by the indicator, e.g. RSI and the middle line.

The space bounded by the curve below the middle line and the middle line itself is area -S1, and above the middle line is +S2.

Posted to https://www.mql5.com/ru/forum/109590 not to interfere.

 

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

Examples of how to use SetTLine().

  1. Orange solid line through the minima of the 15th and current bars.
    SetTLine(Orange, "", Time[15], Low[15], 0, Low[0], True);
  2. Red trend line through the highs of the 35th and 10th bars.
    SetTLine(Red, "", Time[35], High[35], Time[10], High[10]);
  3. Lilac thick ray through the highs of the two previous days.
    datetime d0=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
    datetime d1=TimeCurrent()-24*60*60;
    while (TimeDayOfWeek(d1)==0 || TimeDayOfWeek(d1)==6) d1-=24*60*60;
    d1=StrToTime(TimeToStr(d1, TIME_DATE));
    datetime d2=d1-24*60*60;
    while (TimeDayOfWeek(d2)==0 || TimeDayOfWeek(d2)==6) d2-=24*60*60;
    d2=StrToTime(TimeToStr(d2, TIME_DATE));
    int b2=iBarShift(NULL, 0, d2);     // номер бара начала второго дня
    int b1=iBarShift(NULL, 0, d1);     // номер бара начала первого дня
    int b0=iBarShift(NULL, 0, d0);     // номер бара начала текущего дня
    int n2=iHighest(NULL, 0, MODE_HIGH, b2-b1-1, b1);
    int n1=iHighest(NULL, 0, MODE_HIGH, b1-b0-1, b0);
    datetime t1=Time[n2];
    double   p1=High[n2];
    datetime t2=Time[n1];
    double   p2=High[n1];
    SetTLine(Magenta, "", t1, p1, t2, p2, True, STYLE_SOLID, 3);

HH. Attached is a script to test the SetTLine() function.

Files:
 

Igor, I'm addressing you as a more experienced MQL4 coder.

I started to write a library for Kohonen's network.

I want to make it as flexible and convenient as possible, but I've faced a moment that I can't overcome yet.

Example1:

int& value; // так нельзя, интересует аналог на MQL4, если он есть
 
void AssignValue(int& newValue)
{
   value = newValue;
}
 
void SetValue(int newValue)
{
   value = newValue;
}
 
int init()
{
   int someValue = 5;
   AssignValue(someValue);
   SetValue(10);
   Print(someValue); // очень хочется, чтобы вывелось 10
}

Is it possible to do this using MQL4, and how, if yes?



Example2:

void SetSize(double& matrix[][], int inSize, int outSize)
{
    // требуется установить размеры матрицы, не осилил
}
 
void Init(double& matrix[][])
{
    // допустим, требуется проиниализировать всю матрицу значением 1, также не осилил
}

Again, if it is possible, please give me the code. This example seems realizable to me.



Thank you in advance.

 
TheXpert писал (а) >>
I want to make it most flexible and convenient, but I've faced a moment that I can't overcome yet.
>> Example1:
Is it possible to do it with MQL4 tools and how, if yes?

I understand that you want to organise work with pointers. So that one variable points to another... Or maybe I've got it wrong? Try to explain in words what you need.

TheXpert wrote >>
Example2:
Again, if it is possible to do such a thing, please give me the code. This example seems to me to be implementable.
void start()
{
  double arr[3][2];
  Init(arr);
  for (int i=0; i<3; i++)
  {
    for (int j=0; j<2; j++)
    {
      Print("arr[",i,"][",j,"]=",arr[i][j]);
    }
  }
}
void Init(double& matrix[][])
{
  ArrayInitialize(matrix, 1);
}
 
KimIV писал (а) >>

I understand that you want to organise work with pointers. So that one variable points to another... Or maybe I've got it wrong? Try to explain in words what you need.

Yes, sort of.


About second -- how about to initialize with random values?

Yes, also, I need exactly dynamic arrays.

 
TheXpert писал (а) >>
Yeah, sort of.

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.

TheXpert wrote (a) >>
About the second -- what about initializing with random values?

MathRand()

TheXpert wrote (a) >>
Yeah, also, I need exactly dynamic arrays.
Only the first dimension of the array can be changed programmatically. The ArrayResize() function. The second, third and fourth dimensions have to be set rigidly.