Useful features from KimIV - page 116

 

The SetChannel() function.

This function sets theOBJ_CHANNEL object to an equidistant channel on the current chart.

  • cl- Color of the object. Obligatory parameter.
  • t[]- Array of three values on the time axis.Obligatory parameter.
  • p[]- Array of three values on the price axis.Obligatory parameter.
  • nm- Object name. When the default value is passed -"", the current bar open time is used as the name.
  • ry- Flag of theBOW property. Default value isFalse.
  • st- Line style. Valid values areSTYLE_SOLID(default),STYLE_DASH,STYLE_DOT,STYLE_DASHDOT.
  • wd- Line width. Defaults to1.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 21.03.2013                                                     |
//|  Описание : Установка объекта OBJ_CHANNEL Равноудаленный канал.            |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl  - цвет линии                                                        |
//|    t[] - время открытия бара                                               |
//|    p[] - ценовой уровень                                                   |
//|    nm  - наименование              (  ""  - время открытия текущего бара)  |
//|    ry  - луч                       (False - по умолчанию)                  |
//|    st  - стиль линии               (  0   - простая линия)                 |
//|    wd  - ширина линии              (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetChannel(color cl, datetime& t[], double& p[],
                string nm="", bool ry=False, int st=0, int wd=1) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t[0]<=0) t[0]=Time[20];
  if (p[0]<=0) p[0]=High[20];
  if (t[1]<=0) t[1]=Time[0];
  if (p[1]<=0) p[1]=High[0];
  if (t[2]<=0) t[2]=Time[15];
  if (p[2]<=0) p[2]=Low[15];
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_CHANNEL, 0, 0,0, 0,0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1 , t[0]);
  ObjectSet(nm, OBJPROP_PRICE1, p[0]);
  ObjectSet(nm, OBJPROP_TIME2 , t[1]);
  ObjectSet(nm, OBJPROP_PRICE2, p[1]);
  ObjectSet(nm, OBJPROP_TIME3 , t[2]);
  ObjectSet(nm, OBJPROP_PRICE3, p[2]);
  ObjectSet(nm, OBJPROP_COLOR , cl);
  ObjectSet(nm, OBJPROP_RAY   , ry);
  ObjectSet(nm, OBJPROP_STYLE , st);
  ObjectSet(nm, OBJPROP_WIDTH , wd);
}
ZZY. Attached is a script to test SetChannel() function.
Files:
 

Good afternoon.

I'm using the SetTLine() function from KimIV https://forum.mql4.com/ru/38949/page6#434255 . The problem is that I need two lines (top and bottom), but it doesn't work for me. Made another function SetTLine1() with other variables, but it still doesn't work. How to do it?

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
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=iLowest(NULL, 0, MODE_LOW, b2-b1-1, b1);
int n1=iLowest(NULL, 0, MODE_LOW, b1-b0-1, b0);
datetime t1=Time[n2];
double   p1=Low[n2];
datetime t2=Time[n1];
double   p2=Low[n1];
SetTLine(Magenta, "", t1, p1, t2, p2, True, STYLE_SOLID, 3);   


datetime di0=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
datetime di1=TimeCurrent()-24*60*60;
while (TimeDayOfWeek(di1)==0 || TimeDayOfWeek(di1)==6) di1-=24*60*60;
di1=StrToTime(TimeToStr(di1, TIME_DATE));
datetime di2=di1-24*60*60;
while (TimeDayOfWeek(di2)==0 || TimeDayOfWeek(di2)==6) di2-=24*60*60;
di2=StrToTime(TimeToStr(di2, TIME_DATE));
int bi2=iBarShift(NULL, 0, di2);     // номер бара начала второго дня
int bi1=iBarShift(NULL, 0, di1);     // номер бара начала первого дня
int bi0=iBarShift(NULL, 0, di0);     // номер бара начала текущего дня
int ni2=iHighest(NULL, 0, MODE_HIGH, bi2-bi1-1, bi1);
int ni1=iHighest(NULL, 0, MODE_HIGH, bi1-bi0-1, bi0);
datetime t1i=Time[ni2];
double   p1i=High[ni2];
datetime t2i=Time[ni1];
double   p2i=High[ni1];
SetTLine1(Magenta, "", t1i, p1i, t2i, p2i, True, STYLE_SOLID, 3);
//----
   return(0);
  }
//+------------------------------------------------------------------+

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


void SetTLine1(color cli, string nmi="",
              datetime t1i=0, double p1i=0, datetime t2i=0, double p2i=0,
              bool ryi=False, int sti=0, int wdi=1) {
  if (nmi=="") nmi=DoubleToStr(Time[0], 0);
  if (t1i<=0) t1i=Time[10];
  if (p1i<=0) p1i=Low[10];
  if (t2i<=0) t2i=Time[0];
  if (p2i<=0) p2i=Bid;
  if (ObjectFind(nmi)<0) ObjectCreate(nmi, OBJ_TREND, 0, 0,0, 0,0);
  ObjectSet(nmi, OBJPROP_TIME1 , t1i);
  ObjectSet(nmi, OBJPROP_PRICE1, p1i);
  ObjectSet(nmi, OBJPROP_TIME2 , t2i);
  ObjectSet(nmi, OBJPROP_PRICE2, p2i);
  ObjectSet(nmi, OBJPROP_COLOR , cli);
  ObjectSet(nmi, OBJPROP_RAY   , ryi);
  ObjectSet(nmi, OBJPROP_STYLE , sti);
  ObjectSet(nmi, OBJPROP_WIDTH , wdi);
}
 

You don't need to make two functions. You need to call one with different parameters. You have called two functions, but you have passed an empty name of the object LINE to both of them. By default, the SetTLine() function sets the current bar open time as the name. In your case, this would cause that no matter how many times you calledSetTLine(), each time you created an object with the same name, that is, ONE LINE object.

I have reworked your code. See attachment. And for an example of what your code draws, a picture

Files:
 
KimIV:

You don't need to make two functions. You need to call one with different parameters. You have called two functions, but you have passed an empty name of the object LINE to both of them. By default, the SetTLine() function sets the current bar open time as the name. In your case, this would cause that no matter how many times you calledSetTLine(), each time you created an object with the same name, that is, ONE LINE object.

I have reworked your code. See attachment. And for an example of what your code draws, a picture


I see, thank you.

 

Hello!

I want to say a BIG THANK YOU for your work. I have downloaded 2 files(ByMarketBuy(Sell)+e-SARTrailing) from your website to build my trading system.I sendByMarketBuy(Sell) scripton EUR/USD pair on 1 screen, prescribing MAGIC 30 for one order andMAGIC 60 for another order (respectively M30 and H1) ande-SARTrailing advisor on 2 and 3 screens withSAR.TF=30 and 60 settingsrespectively. And since two orders are open on the same currency pair, so they go co-rotated and it turns out that withoutMagicNumber Advisorse-SARTrailing on two screens will conflict with each other. I have a GREATREQUESTto youif you could amend the advisor (to write) such a feature asMagicNumber may be such a supplement would appreciate many. And this will work on all timeframes at the same time without conflict with each other regardless of directionality.

Many thanks in advance!

 
tim-time:

I have a GREAT REQUEST to you if you could tweak your Expert Advisor withMagicNumberfunction.

Thanks for the tip. I added a filter for magicians...
 

GetTimeOpenBar() function.

This function returns the open time of an arbitrary symbol and arbitrary timeframe bar. Generally, it is just a combination of basic functions iBarShift() and iTime(). Therefore, there is nothing new here, and the use of a particular variant is a matter of convenience. You can pass the following optional parameters to the function

  • sy- Name of trade instrument (symbol). Values "" and NULL mean the current symbol. Default value is "".
  • tf- Time frame. Default value - 0 - current timeframe.
  • dt- Date and time. Default value - 0 - current time.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 25.01.2012                                                     |
//|  Описание : Возвращает время открытия бара.                                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//|    tf - таймфрейм                  (    0       - текущий)                 |
//|    dt - дата/время                 (    0       - текущее)                 |
//+----------------------------------------------------------------------------+
datetime GetTimeOpenBar(string sy="", int tf=0, int dt=0) {
  if (sy=="" || sy=="0") sy=Symbol();
  if (tf==0) tf=Period();
  if (dt==0) dt=TimeCurrent();
  
  int sh=iBarShift(sy, tf, dt, False);

  return(iTime(sy, tf, sh));
}

 
KimIV:
Thank you for the tip. I've added a filter for magicians...

HELLO!

WOW !!! THAT'S THE PACE !!! (I do it myself or I say NO!)

AHUGE RESPECTFOR PROFESSIONALS!(A professional must know all the smallest details + hard work in their field and of course the experience that accumulates over the years).

I am engaged in the built-in furniture already 4 5 years and 1 5 years finishes Forex trading (hard work+experience of successful and unsuccessful moments in trade, it remains to learn the smallest details).

MY GOAL IS TO BECOME A PROFESSIONAL IN TRADING.

I APPRECIATEYOUR HELP!

WITH RESPECT!

 

I have put together the ErrorRU() function, which returns a short or detailed Russian description of an error by its code. Both errors returned by the trade server and errors of executing MQL programs are detected. Not all errors, however, have a detailed description with recommendations "What to do", but that's how it is.

I am publishing the function in the script for testing it.

If someone needs a variation in the form of MQH-file, you can get it from my website.

Files:
 

Hello!

Is it possible to add PUSH-notifications to youre-SignalOfTrade EA?

https://www.mql5.com/ru/forum/6960

https://www.mql5.com/ru/docs/common/sendnotification

(Leased VPS server refuses to give the data SMTP-server which should be specified in MT4 mail settings for work of the advisor withUseSendMail=True- email. )

Thanks in advance!