Let's go SetLastError!!! - page 5

 
vit46:

And it's not unconditional zeroing but only if last_error_fifo == 0. In short, it's the same as eggs in profile. check what the function returned before checking for errors.

 
Roger:
Develop the topic.

Exactly for you, see :

OrderSend() termination options;

1. No error. You still call GetLastError() - in principle it's OK if the previous error is read, processed and reset.

IMHO - you don't have to.

2. There is an error - when calling GetLastError (), as far as I understand, you analyze one single error, although there may be many of them.

IMHO, it is more correct:

        ticket=OrderSend(symbol,cmd,op_v,ordprice,slippage,0,0,comment,magic,expiration,arrow_color);
        if(ticket<0)
        {
            err = GetLastError();
            int err_res = ErrReaction(err);
.........................................

The last one is ErrReaction(err) - this is error handling.

For example, like this :

int ErrReaction(int err)
{
    switch(err)
    {
        case ERR_TRADE_NOT_ALLOWED    :
                 Print("TRADE NOT ALLOWED ! SWITCH ON option \' Allow live trading\' (Необходимо включить опцию \'Разрешить советнику торговать\')");
        case ERR_INVALID_FUNCTION_PARAMSCNT :    
        case ERR_INVALID_FUNCTION_PARAMVALUE :    
        case ERR_INVALID_STOPS        : 
        case ERR_INVALID_TRADE_VOLUME : 
        case ERR_MARKET_CLOSED        : 
        case ERR_TRADE_DISABLED       : 
        case ERR_NOT_ENOUGH_MONEY     : 
                 return(-err);
        case ERR_NO_CONNECTION        :
............................................
        case ERR_BROKER_BUSY          : 
        case ERR_TRADE_CONTEXT_BUSY   : 
..............................
        case ERR_PRICE_CHANGED : 
        case ERR_OFF_QUOTES    : 
        case ERR_REQUOTE       : 
.................................................
        default: break;
    }//switch(err)
    return(0);
}//int ErrReaction(int err)

The processing function divides the errors into "fixable" and "unrecoverable" - the "fixable" one tries to eliminate, the code of the unrecoverable one returns back - for processing in an external (calling) procedure.

 
sergeev:



Well anyway my cockroaches are cooler because there is no need to check what each function returned so the code looks better... plus you can organise your own error codes.
 
vit46:
plus you can organise your own error codes.


we somehow have enough to make our own as well.

 
Roger:

It depends on your logic. After all, you can do processing of every error, and you can do only those which are important in this situation.

It is desirable, of course, to have a function for processing all of the most significant errors, and then the logic inherent in the Expert Advisor will "adjust" the priorities.

Separately, I apologize to the topicstarter if my question leads away from the main direction of the topic.

 
sergeev:


We somehow have enough to make our own as well.



Who do the inventors of MQL5 try so hard to create SetUserError... they reserved as many as 65535 error codes for themselves, and anything above that is ok, you can arrange your own :)
 
VladislavVG:

Just for you, see :

2. There is an error - when calling GetLastError () as far as I understand you analyze one single error, although there may be many.

IMHO - more correct variant:

The last one is ErrReaction(err) - this is error handling.

It is this option that is debatable. If you do not reset the error and there is no error after OrderSend, you will still process the old error.
 

vit46:

Ознакомьтесь с этим материалом. imho, не повредит.

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

 
charter:

It is desirable, of course, to have a function for processing all the most significant errors, and then the logic inherent in the Expert Advisor will "correct" the priorities.


For example, I believe that it is enough to try to open an order 5 times and then to stop trying, while you may think that you need to open an order 20 times or "to win".
 
Roger:

I, for example, think it is enough to try to open an order 5 times and then stop trying, but you may think you have to try 20 times or open "until you win".

No, I am not counting anything. I do not have my own firm and unambiguous opinion, which is why I am asking you to recommend the most decent error-correcting feature.
Reason: