Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 880

 
Mikhail Rudyk:

the robot only stands on this chart but trades the same options as they do for robots

Insert this line.

void Open(int lot,string comment)
   {
               bool eror=false;
               int step=0;
               if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)==1)
                  {
                           while(eror==false&&step<10)
                              {
                                 double bid=SymbolInfoDouble(symbolName,SYMBOL_BID);
                                 ResetLastError();
                                 eror=Trade.Buy(lot,symbolName,bid,0,0,comment);
                                 step++;
                                 Sleep(200);
                                 if(eror==false)Print("error - ",GetLastError());
                              }
                  }
   }
 

put

but I don't think resetting the error will help.

 
Mikhail Rudyk:

but I don't think resetting the error will help.

Also.

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

void Open(int lot,string comment)
   {
               bool eror=false;
               int step=0;
               if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)==1)
                  {
                           while(eror==false&&step<10)
                              {
                                 double bid=SymbolInfoDouble(symbolName,SYMBOL_BID);
                                 ResetLastError();
                                 // eror=Trade.Buy(lot,symbolName,bid,0,0,comment); // закомментировать
                                 eror=OrderSend(symbolName, OP_BUY, lot, bid, 0, 0, 0, comment);
                                 step++;
                                 Sleep(200);
                                 if(eror==false)Print("error - ",GetLastError());
                              }
                  }
   }
 

I already did that and it worked.

But the fact of the error is still unresolved.

thanks so much for your help

while(eror==false&&step<10)
{
double bid=SymbolInfoDouble(symbolName,SYMBOL_BID);
ResetLastError();
eror=Trade.Buy(lot,symbolName,bid,0,0,comment);
step++;
Sleep(200);
if(eror==false)
{
Print("error - ",GetLastError());
if(GetLastError()==4754){OnInit();}
}
}

 
Mikhail Rudyk:

the fact of the error is unresolved.

That's why I suggested this option.

 
fxsaber:

That's why I suggested this option.

Well, I'll give it a try.

But why doesn't the standard class work?

 
Mikhail Rudyk:

Well, I'll give it a try.

But why doesn't the standard class work?

If the alternative library works, it will become clear where to dig.

I can't reproduce the problem with each of the libraries.

 
Mikhail Rudyk:

I already did this and it worked.

while(eror==false&&&step<10)
{
double bid=SymbolInfoDouble(symbolName,SYMBOL_BID);
ResetLastError();
eror=Trade.Buy(lot,symbolName,bid,0,0,comment);
step++;
Sleep(200);
if(eror==false)
{
Print("error - ",GetLastError());
if(GetLastError()==4754){OnInit();}
}
}

This should not work. 4754 occurs when OrdersTotal is greater than zero, but OrderSelect or OrderGetTicket get screwed up.

This is very rare, but not in this case. The server/symbol is so specific here that the same thing happens with positions, only with error 4753.

Already prepared to have to make adjustments to the alternate bible, as the situations that arise pull a lot of logic down. For there you send a market order, it comes to the server, creates a position and closes it at the same millisecond. And the terminal receives information retroactively because of the ping.

I was pleasantly surprised that everything worked perfectly.


Server/symbol itself dodosil, error did not occur.


SZY The pose cannot be opened manually, only through MQL.

 

I meant that it helped that the robot didn't hang

 
Mikhail Rudyk:

I meant that it helped the robot not to hang

Then show OnInit. Right now it looks like nonsense.

Reason: