Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1029

 
Roman Kutemov:

advise how to determine the day in mt5 ? an analogue of DayOfYear from mt4

this is the function to write

if (TimeDayOfYear(transaction_time)==DayOfYear())

https://www.mql5.com/ru/docs/constants/structures/mqldatetime

Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура даты
Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура даты
  • www.mql5.com
Порядковый номер в году day_of_year в високосном году, начиная с марта, будет отличаться от порядкового номера соответствующего дня в невисокосном году.
 

I've read that, I just don't know how to put it in the code

 
Roman Kutemov:

advise how to determine the day in mt5 ? an analogue of DayOfYear from mt4

this is the function to write

if (TimeDayOfYear(transaction_time)==DayOfYear())

Example code:

   MqlDateTime STimeTransaction,STimeCurrent;
   ResetLastError();
   if(TimeToStruct(transaction_time,STimeTransaction))
     {
      if(TimeToStruct(TimeCurrent(),STimeCurrent))
        {
         if(STimeTransaction.day_of_year==STimeCurrent.day_of_year)
           {
            //--- your code

           }
        }
      else
         Alert("ERROR STimeCurrent: ",GetLastError());
     }
   else
      Alert("ERROR STimeTransaction: ",GetLastError());

There are twoMqlDateTime structures -STimeTransaction and STimeCurrent. In theSTimeTransaction structure we convert transaction time (transaction_time), and in theSTimeCurrent structure - last known time of the trade server.

Then we simply compareday_of_year field of these two structures(STimeTransaction andSTimeCurrent)

 
Vladimir Karputov:

Example code:

TwoMqlDateTime structures -STimeTransaction and STimeCurrent. In theSTimeTransaction structure we convert transaction time (transaction_time), and in theSTimeCurrent structure we convert the last known time of the trade server.

Then, we simply compareday_of_year field of these two structures(STimeTransaction andSTimeCurrent)

cool, thanks

 

A word of advice to an old man...

For some reason, printing does not work when debugging the Expert Advisor.

I.e. there is a piece of program:

if(IsNewBar)
       {
     Print("Buy_opened=",Buy_opened ,"  Sell_opened=",Sell_opened,"   Новый бар",New_Time[0]);
     int fileHandle=FileOpen("test.txt",FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_UNICODE,0,0); 
     FileWrite(fileHandle,"Buy_opened=",Buy_opened ,"  Sell_opened=",Sell_opened,"   Новый бар",New_Time[0]);
     Alert("Buy_opened=",Buy_opened ,"  Sell_opened=",Sell_opened,"   Новый бар",New_Time[0]);
       }


And it doesn't print anything. I even removed if(IsNewBar) to print on every tick - but nothing.

I looked through all the tabs like "Expert Advisor", "logs", "logs" - nothing.

What is the problem? I had no problems with MT4, but I have no idea where to go with MT5... I don't know where to go... I don't know where to look...


Yes, the Expert Advisor is not running in "optimization" mode, it's just running on historical data

Отладка кода - Разработка программ - MetaTrader 5
Отладка кода - Разработка программ - MetaTrader 5
  • www.metatrader5.com
В MetaEditor встроен отладчик — инструмент, который позволяет проверить работу программы по шагам (по отдельным функциям). Вы расставляете в коде программы точки останова — места, в которых исполнение программы должно быть приостановлено. Затем запускаете программу на обычном графике или в тестере стратегий. Как только исполнение программы...
 
Oldman_Evgeny:

A word of advice to an old man...

For some reason, printing does not work when debugging the Expert Advisor.

I.e. there's a piece of program:


And it doesn't print anything. I even removed if(IsNewBar) to print on every tick - but nothing.

I looked through all the tabs like "Expert Advisor", "logs", "logs" - nothing.

What is the problem? I had no problems with MT4, but I have no idea where to go with MT5... I don't know where to go... I don't know where to look...


Yes, the Expert Advisor is not running in "optimization" mode, it's just running on historical data

See the logs in the "Tester" folder.

 
Alexey Viktorov:

See the logs in the "Tester" folder.

There's all sorts of stuff in the "Tester" folder logs, but the print I'm looking for, i.e. from the programme, isn't there...
 
Oldman_Evgeny:
The logs of the "Tester" folder are full of all sorts of stuff, but the printout I'm looking for, i.e. from the program, is not there...

There's also a folder called "Agent-127.0.0.1-3000" which also has logs.

 
Alexey Viktorov:

There's also a folder "Agent-127.0.0.1-3000" with logs in it too.

Miracle! Removed ALL the logs in the tester and printing appeared in the "Log" tab. Amazing!

I can't imagine how it happened! )))) But the fact is - it prints!

Thanks for the help!

 

What flag should be set to open a file to start the Expert Advisor writing data into the file in the tester, so that after a run in the tester the written file can be found in the "MQL5\Files" folder?

I tried it this way: FILE_WRITE|FILE_TXT - i cannot find where the tester has saved the file.

I tried it this way: FILE_WRITE|FILE_TXT|FILE_COMMON - everything is as described in Help, I find the file in "Roaming\MetaQuotes\Terminal\Common\Files".


but I want the file in "MQL5\Files" !!!

Reason: