Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1445

 
Aleksandr Slavskii #:

I think fxsaber posted a bootnik and a description of how to use it, but I don't remember where and how.

If I'm not mistaken, you need to put the bootstrap in the terminal folder C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\E98C5173D8A802F9B8F133E800FDDE2B.

And run the botnick every time before starting the terminal.

The solution is not particularly convenient, but if there is no other, then ...


Shit. First I posted it, and then I saw that the bootnik is forbidding logs in the tester.

I'm sorry, I can't help you.

Isn't it easier to run the bootloader than to delete logs manually?


What's happening on the site? I paste one picture, I see the one that should be there, but when I paste a message, I see a different picture....

Ooh! I got it...

Files:
01.png  23 kb
 
Aleksandr Slavskii #:

I think fxsaber posted a bootnik and a description of how to use it, but I don't remember where and how.

If I'm not mistaken, you need to put the bootstrap in the terminal folder C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\E98C5173D8A802F9B8F133E800FDDE2B.

And run the botnick every time before starting the terminal.

The solution is not particularly convenient, but if there is no other, then ...


Shit. First I posted it, and then I saw that the bootnik is forbidding logs in the tester.

I'm sorry, I can't help you.

I thought to tick a box somewhere and that's it ))
well, I have to put up with it,
thanks for the answer.
 
Evgeny Dyuka #:
I thought I'd tick a box somewhere and that's it ))
anyway, I'll have to put up with it,
thanks for the reply.

Did you write that code yourself? Maybe you can show a piece of code how db is called and a few lines after the call. Something seems to me that it says print error.....

 
Alexey Viktorov #:

Did you write that code yourself? Maybe you can show a piece of code how db is called and a few lines after the call. Something seems to me that it says to print an error....

The task is to write the current time to the database every 10 seconds. It is done by the same Expert Advisor, but on 4 charts.
To separate them by time, I added a crutch in the form of Sleep() random time - from 0 to 3 seconds.
And 10 attempts to connect.
The log showed that at most on the second attempt everything works, i.e. in general it works reliably.

.
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void db_update_lastseen(string symbol)
  {
   string comm = "UPDATE LastSeen SET utime='" +
                 IntegerToString((int)TimeGMT()) +
                 "' WHERE who='mt5' AND symbol='" + symbol + "'";
   if(!db_exe("db_update_lastseen", comm))
      Telegram("⚠MT5 DB ERROR db_update_lastseen() " + symbol, DevChannel);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool db_exe(string who, string comm, bool readonly = false)
  {
   ResetLastError();
   int count = 0;
   bool repeat = true;
   int dbmt = INVALID_HANDLE;
   while(repeat)
     {
      count++;
      Sleep((int)((float)MathRand() / 10));
      if(count > 10)
        {
         Print("DB: " + who + " failed with code ", GetLastError(), " DatabaseOpen ", " count: ", count);
         return false;
        }
      if(readonly)
         dbmt = DatabaseOpen(path_to_db, DATABASE_OPEN_READONLY);
      else
         dbmt = DatabaseOpen(path_to_db, DATABASE_OPEN_READWRITE);
      if(dbmt == INVALID_HANDLE)
        {
         DatabaseClose(dbmt);
         continue;
        }
      else
        {
         if(!DatabaseExecute(dbmt, comm))
           {
            DatabaseClose(dbmt);
            continue;
           }
         else
           {
            DatabaseClose(dbmt);
            return true;
           }
        }
     }
   DatabaseClose(dbmt);
   return false;
  }
 
Evgeny Dyuka #:
The task is to write the current time into the database every 10 seconds. It is done by the same Expert Advisor, but on 4 charts.
To separate them by time I added a crutch in the form of Sleep() random time - from 0 to 3 seconds.
And 10 attempts to connect.
Log showed that at most on the second attempt everything works, i.e. in general it works reliably.

.

So here is the line that is printed to the log.

         Print("DB: " + who + " failed with code ", GetLastError(), " DatabaseOpen ", " count: ", count);

It is enough to comment it out by putting // in front of it or remove it altogether and all questions will be removed if there is no other Print() anywhere else;

 
Alexey Viktorov #:

So here's the line that prints to the magazine

It is enough to comment it out by putting // in front of it or delete it completely and all questions will be removed, if there is no other Print() anywhere else;

This line will be printed if it fails with 10 attempts.
The function itself prints the error.


 
Evgeny Dyuka #:

This line will be printed if the function fails after 10 attempts.
The error is printed by the function itself.


I see. It is printed when trying to work with db. We need to see if there is a validity check of the db handle before using the database.

Here you called the function

void db_update_lastseen(string symbol)
  {
   string comm = "UPDATE LastSeen SET utime='" +
                 IntegerToString((int)TimeGMT()) +
                 "' WHERE who='mt5' AND symbol='" + symbol + "'";
   if(!db_exe("db_update_lastseen", comm))
      Telegram("⚠MT5 DB ERROR db_update_lastseen() " + symbol, DevChannel);
  }

You tried to open the db, got an error, sent a message to telegram....

And where you use the dbmt variable, do you check its value there?

if(dbmt < 0)
// ничего делать нельзя. База не открыта…

or like this

if(dbmt >= 0)
 {
  // Базу можно использовать.
 }
 
Alexey Viktorov #:

I see. This is printed when trying to work with db. We need to see if there is a validity check of the db handle before using the database.

Here you have called the function

You tried to open the db, got an error, sent a message to telegram...

And where you use the dbmt variable do you check its value?

or like this

Yes, I check it in db_exe() and send it to retry. And db_exe() will return False if it fails 10 times (it has never returned it).
if(dbmt == INVALID_HANDLE)
        {
         DatabaseClose(dbmt);
         continue;
        }
I think that the library of work with the base sends an error and, it seems, it does not handle the situation when the base is locked.
In Python such a problem does not occur, apparently it is built in queuing and waiting.

Thank you for your answers.
 
Evgeny Dyuka #:
Yes, I check in db_exe() and send it to retry. But db_exe() will return False if it fails 10 times (never returned).
I think the library of work with the base sends an error and it seems that it does not handle the situation when the base is locked.
In Python such a problem does not occur, apparently it has queuing and waiting.

Thank you for your answers.

1. If the base handle is not retrieved, you don't need to close the base.

2. If INVALID_HANDLE is received, why continue execution of the programme? I think in this case it is better to abort, return

I am now repeatedly trying to open and close a non-existent base and I can not get an error printout. I think that this printout comes at the moment of creating queries to the base, which could not be opened.

 
Alexey Viktorov #:

1. If the base handle is not received, the base does not need to be closed.

2. If INVALID_HANDLE is received, why continue execution of the programme? I think in this case it is better to interrupt, return

I am now repeatedly trying to open and close a non-existent database and I can't get the error printout. I think that this printout comes at the moment of creating queries to the base, which could not be opened.

I will make a minimal test Expert Advisor that will update the record in the database every second. Let's run it on 10 pairs and everything will be clear. I will post it here...
Reason: