Self-learning the MQL5 language from scratch - page 79

 
Valeriy Yastremskiy:

Artem Trishkin answered the same question to me, because it's a link (uppersand), so it can stand in any place. should try without spaces for the purity of the experiment.

Thank you, Valery! Will definitely consider this point if I ever run into a similar problem.

Merry Christmas!

Sincerely, Vladimir.

 

Happy trading and good mood everyone!

I continue studying the MQL5 programming language. I have modified the previously published code a bit and this is what I have got:

input string Symbol_Main="EURUSD";          //Валютная пара, на которую ставим советник
input ENUM_TIMEFRAMES Time_Frame=PERIOD_H1; //Таймфрейм, на который ставим советник

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   /* Определим график валютной пары и таймфрейм, на который будем устанавливать советник. */
   /* Если текущий график валютной пары и текущий таймфрейм совпадают со входными параметрами */
   if(_Symbol==Symbol_Main && _Period==Time_Frame)
     {
      /* выводим окно сообщений на торговом терминале и продолжаем работу советника */
      MessageBox("Работа советника разрешена! Продолжим!");
      return(INIT_SUCCEEDED); //возвращаем для функции OnInit значение означающее "удачная инициализация"
     }
   /* Если текущий график валютной пары и текущий таймфрейм не совпадают со входными параметрами */
   if(_Symbol!=Symbol_Main && _Period!=Time_Frame)
     {
      /* выводим окно сообщений на торговом терминале и закрываем советник */
      MessageBox("Не совпадают валютная пара и таймфрейм! Выходим!");
      return(INIT_FAILED); //возвращаем для функции OnInit значение означающее "неудачная инициализация"
     }
   /* Если текущий график валютной пары не совпадает со входным параметром */
   if(_Symbol!=Symbol_Main)
     {
      /* выводим окно сообщений на торговом терминале и закрываем советник */
      MessageBox("Не совпадает валютная пара! Выходим!");
      return(INIT_FAILED); //возвращаем для функции OnInit значение означающее "неудачная инициализация"
     }
   /* Если текущий таймфрейм не совпадает со входным параметром */
   if(_Period!=Time_Frame)
     {
      /* выводим окно сообщений на торговом терминале и закрываем советник */
      MessageBox("Не совпадет таймфрейм! Выходим!");
      return(INIT_FAILED); //возвращаем для функции OnInit значение означающее "неудачная инициализация"
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+

Perhaps someone will need it.

Regards, Vladimir.

 

Good day and good mood everyone!

I have some free time and decided to continue my self-study. But all of a sudden I ran into a problem. Earlier, when I made a request like this to the trade server in my Expert Advisor Trailing_Stop_(v.2).mq5:

   /*  Создадим запрос на сервер и получим ответ с результатом */
   MqlTradeRequest request= {0};
   MqlTradeResult result= {0};

there were no problems during code compilation. Now the compiler generates the following error:

cannot convert 0 to enum'ENUM_TRADE_REQUEST_ACTIONS' Trailing_Stop_(v.2).mq5 411 30

If I remove a zero after request in curly brackets,

   /*  Создадим запрос на сервер и получим ответ с результатом */
   MqlTradeRequest request= {};
   MqlTradeResult result= {0};

I don't get an error then. Please help me, what is the reason for this?

Regards, Vladimir.

 
MrBrooklin:

Good day and good mood everyone!

I have some free time and decided to continue my self-study. But all of a sudden I ran into a problem. Earlier, when I made a request like this to the trade server in my Expert Advisor Trailing_Stop_(v.2).mq5:

there were no problems during code compilation. Now the compiler generates the following error:

cannot convert 0 to enum'ENUM_TRADE_REQUEST_ACTIONS' Trailing_Stop_(v.2).mq5 411 30

If I remove a zero after request in curly brackets,

I don't get an error then. Please help me, what is the reason for this?

Regards, Vladimir.

Yes, now do not write zero for zeroing.

ENUM_TRADE_REQUEST_ACTIONS , an enumeration that lacks the value "0".

cannot convert 0 to enum 'ENUM_TRADE_REQUEST_ACTIONS'


The correct way would be:

MqlTradeRequest request={};

 
Vladimir Karputov:

Yes, now don't write zero for zeroing.

Thank you, Vladimir!

You live and learn a long time! If the MQL5 Reference developers would correct this everywhere, it would be great!

Sincerely, Vladimir.

 

Good morning everyone!

I am continuing my self-study of MQL5 programming language. I decided to write a function for getting signal from ZigZag indicator. I started to study it thoroughly and it immediately raised some questions. I have it in its input parameters:

input int Depth      = 12;  // Depth
input int Deviation  = 5;   // Deviation
input int Backstep   = 3;   // Backstep

I'm not fluent in English so I have to use Google Translator. What is the pure translation:

Depth - глубина
Deviation - отклонение
Backstep - шаг назад

Questions:

  1. If depth, depth of what?
  2. If deviation, deviation from what, from what parameter or value?
  3. If a step backwards, why a step backwards? Isn't it moving forward?

Dear experts, help me to understand!

Sincerely, Vladimir.

 
MrBrooklin:

Good morning everyone!

I am continuing my self-study of MQL5 programming language. I decided to write a function for getting signal from ZigZag indicator. I started to study it thoroughly and it immediately raised some questions. I have it in its input parameters:

I'm not fluent in English so I have to use Google Translator. What is the pure translation:

Questions:

  1. If depth, depth of what?
  2. If deviation, deviation from what, from what parameter or value?
  3. If a step backwards, why a step backwards? Isn't it moving forward?

Dear experts, help me to understand!

Sincerely, Vladimir.

Elementary - search to help, " Doesn't it move forward " - the whole story moves backwards here!!!! :-)

https://www.mql5.com/ru/code/7796


Depth is the minimum number of bars on which there will not be a second high (low) less (more) by Deviation pips than the previous one, i.e. the ZigZag can always diverge, but converge (or shift the whole) more than by Deviation, the ZigZag can only after the Depth bars. The Backstep is the minimum number of bars between highs (lows).


In the search box, type in: e.g. zigzag parameters, https://www.mql5.com/ru/search#!keyword=%D0%B7%D0%B8%D0%B3%20%D0%B7%D0%B0%D0%B3%20%D0%BF%D0%B0%D1%80%D0%B0%D0%BC%D0%B5%D1%82%D1%80%D1%8B&amp;page=2</b></p>

PS elementary things...

ZigZag
ZigZag
  • www.mql5.com
ZigZag отслеживает и соединяет между собой крайние точки графика отстоящие друг от друга не менее чем на заданный процент по шкале цены.
 
Roman Shiredchenko:

Elementary - search to help, " Isn't it moving forward " - the whole story is moving backwards here!!!! :-)

https://www.mql5.com/ru/code/7796


Depth is the minimum number of bars on which there will be no second maximum (minimum) less (more) than the previous one by Deviation pips, i.e. the ZigZag can always diverge, but it can converge (or shift the whole) more than by Deviation, the ZigZag can only after Depth bars. The Backstep is the minimum number of bars between highs (lows).


In the search box, type in: e.g. zigzag parameters, https://www.mql5.com/ru/search#!keyword=%D0%B7%D0%B8%D0%B3%20%D0%B7%D0%B0%D0%B3%20%D0%BF%D0%B0%D1%80%D0%B0%D0%BC%D0%B5%D1%82%D1%80%D1%8B&amp;page=2</b></p>

PS elementary things...

Thank you very much, Roman! You gave the most concise, but at the same time, understandable explanation.

Respectfully, Vladimir.

 
MrBrooklin:

Thank you very much, Roman! You have given the most concise, but at the same time understandable explanation.

Respectfully, Vladimir.

Thank you for checking it out, I'm being friendly, no backstabbing! It's with a smile!
 

Good day everyone!

While testing one Expert Advisor, I encountered a problem. It has the following code of EA initialization function:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- достаточно ли количество баров для работы
   if(Bars(_Symbol,_Period)<60) // общее количество баров на графике меньше 60?
     {
      Alert("На графике меньше 60 баров, советник не будет работать!!");
      return(-1);
     }
//--- получить хэндл индикатора Bollinger Bands и DEMA
   BolBandsHandle=iBands(NULL,PERIOD_M30,bands_period,bands_shift,deviation,PRICE_CLOSE);
   demaHandle=iDEMA(NULL,PERIOD_D1,dema_period,0,PRICE_CLOSE);
//--- Нужно проверить, не были ли возвращены значения Invalid Handle
   if((BolBandsHandle<0) || (demaHandle<0))
     {
      Alert("Ошибка при создании индикаторов - номер ошибки: ",GetLastError(),"!!");
      return(-1);
     }

   return(0);
  }

While testing the EA I get messages in the log:

2021.10.31 13:19:25.752 Core 2  genetic pass (0, 288) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:26.835 Core 2  genetic pass (0, 298) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:26.921 Core 1  genetic pass (0, 42) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:27.847 Core 2  genetic pass (0, 318) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:27.848 Core 2  genetic pass (0, 326) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:29.907 Core 2  genetic pass (0, 359) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:29.907 Core 2  genetic pass (0, 371) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:30.009 Core 1  genetic pass (0, 102) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:30.009 Core 1  genetic pass (0, 105) tested with error "OnInit returned non-zero code -1" in 0:00:00.000
2021.10.31 13:19:31.044 Core 1  genetic pass (0, 122) tested with error "OnInit returned non-zero code -1" in 0:00:00.000

и т.д.

I found out that the problem is in checking the Bollinger Bands and DEMA indicators handles. I have already checked Bollinger Bands and DEMA indicators handles, so I have a question: What should I change in my code to correct these errors?

Regards, Vladimir.