Can you tell me if the error handling block below is spelled correctly or if there's something wrong? Don't swear right away ))))
//+------------------------------------------------------------------+//| Функция обработки ошибок |//+------------------------------------------------------------------+if(GetLastError()>=0)
{
switch(_LastError)
{ // Преодолимые ошибки case4:Sleep(3000); // Простое решениеbreak; // Выход из функцииcase6:Sleep(10000); // Простое решениеbreak; // Выход из функцииcase130:Sleep(3000);RefreshRates(); // Обновим данныеbreak; // Выход из функцииcase135:Sleep(3000);RefreshRates(); // Обновим данныеbreak; // Выход из функцииcase136:Sleep(3000);RefreshRates(); // Обновим данныеbreak; // Выход из функцииcase137:Sleep(3000); // Простое решениеbreak; // Выход из функцииcase146:Sleep(3000); // Простое решениеbreak; // Выход из функцииdefault:break; // Другие варианты // Выход из функции
}
}
}
Can you tell me if the error handling block below is spelled correctly or if there is something wrong? Don't swear right away ))))
In my opinion, error handling should be in the form of a user-defined function, which should be called after any action involving access to the server.
For example OrderSend() returns order ticket or -1 in case of failure, i.e. in case of error. So, it's necessary to call the error handler in case of unsuccessful command execution and pass the error code into it. And in the error handler, we should provide a return value at which the failed action is repeated or at another value it is stopped.
For example the prices have changed, RefreshRates(); and try again, and if there is not enough money it is probably better to stop trying.
In my opinion, error handling should be in the form of a user-defined function, which should be called after any action related to server access.
For example OrderSend() returns order ticket or -1 in case of failure, i.e. in case of error. So, you should call the error handler in case of unsuccessful command execution and pass the error code into it. And in the error handler, we should provide a return value at which the failed action is repeated or at another value it is stopped.
For example the prices have changed, RefreshRates(); and retry, and in case of insufficient funds it is probably better to stop trying.
I have functions after GetLastError and if there is an error, won't it go to this block (as written) and commands won't be executed? I understand the chain, e.g. OrderSend() -> GetLastError -> error block Sleep(3000) RefreshRates() -> exit the block and if conditions remain OrderSend() is requested again. Or my reasoning and concepts are wrong. I understand you want to write the return value 1 or 0 in the block, but my functions are simple not related to boolean values like SignalBuy, if I understand correctly, the return values should be returned there.
I have GetLastError after functions and if an error occurs, won't it go to this block (as written) and commands won't be executed? I understand the chain, e.g. OrderSend() -> GetLastError -> error block Sleep(3000) RefreshRates() -> exit the block and if conditions remain OrderSend() is requested again. Or my reasoning and concepts are wrong. I understand you want to write the return value 1 or 0 in the block, but my functions are simple not related to boolean values like SignalBuy, if I understand correctly, the return values should be returned there.
Make a loop on the number of trade attempts at error. Refresh the trading environment. Reset the value of the previous error and send a trade request with a check for the returned result. If an error is returned, analyze it and, depending on the error code, either terminate the cycle completely or perform the necessary actions to correct the error and proceed to the next iteration of the cycle. If the trade operation was successful, interrupt the loop and return to the calling program the value corresponding to the program logic for further processing of the trade request result (either the function execution success flag or the open order ticket number, etc.).
Pokrov, I told you what you're looking at...
Here is the answerhttps://www.mql5.com/ru/forum/131277/page295#455199
Thanks to the author.
Can you tell me if the error handling block below is spelled correctly or if there's something wrong? Don't swear right away ))))
How can the indicator save the value history to a file (and load it later)? Are there any ready-made solutions?
Can you tell me if the error handling block below is spelled correctly or if there is something wrong? Don't swear right away ))))
In my opinion, error handling should be in the form of a user-defined function, which should be called after any action involving access to the server.
For example OrderSend() returns order ticket or -1 in case of failure, i.e. in case of error. So, it's necessary to call the error handler in case of unsuccessful command execution and pass the error code into it. And in the error handler, we should provide a return value at which the failed action is repeated or at another value it is stopped.
For example the prices have changed, RefreshRates(); and try again, and if there is not enough money it is probably better to stop trying.
In my opinion, error handling should be in the form of a user-defined function, which should be called after any action related to server access.
For example OrderSend() returns order ticket or -1 in case of failure, i.e. in case of error. So, you should call the error handler in case of unsuccessful command execution and pass the error code into it. And in the error handler, we should provide a return value at which the failed action is repeated or at another value it is stopped.
For example the prices have changed, RefreshRates(); and retry, and in case of insufficient funds it is probably better to stop trying.
I have functions after GetLastError and if there is an error, won't it go to this block (as written) and commands won't be executed? I understand the chain, e.g. OrderSend() -> GetLastError -> error block Sleep(3000) RefreshRates() -> exit the block and if conditions remain OrderSend() is requested again. Or my reasoning and concepts are wrong. I understand you want to write the return value 1 or 0 in the block, but my functions are simple not related to boolean values like SignalBuy, if I understand correctly, the return values should be returned there.
I have GetLastError after functions and if an error occurs, won't it go to this block (as written) and commands won't be executed? I understand the chain, e.g. OrderSend() -> GetLastError -> error block Sleep(3000) RefreshRates() -> exit the block and if conditions remain OrderSend() is requested again. Or my reasoning and concepts are wrong. I understand you want to write the return value 1 or 0 in the block, but my functions are simple not related to boolean values like SignalBuy, if I understand correctly, the return values should be returned there.