Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 845

 
eddy:
Pokrov, I told you what you're looking at...
No offence, two opinions are better than one))) Thank you too!
 
Hi all, could you please tell me how to set the EA not to place an order if the last trade was closed today?
 

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 ))))

//+------------------------------------------------------------------+
//| Функция обработки ошибок                                          |
//+------------------------------------------------------------------+
if(GetLastError()>=0)                          
{
   switch(_LastError)  
{                                               // Преодолимые ошибки            
      case  4:Sleep(3000);                      // Простое решение
      break;                                    // Выход из функции
      case  6:Sleep(10000);                     // Простое решение
      break;                                    // Выход из функции
      case 130:Sleep(3000);RefreshRates();      // Обновим данные
      break;                                    // Выход из функции
      case 135:Sleep(3000);RefreshRates();      // Обновим данные
      break;                                    // Выход из функции
      case 136:Sleep(3000);RefreshRates();      // Обновим данные
      break;                                    // Выход из функции
      case 137:Sleep(3000);                     // Простое решение
      break;                                    // Выход из функции
      case 146:Sleep(3000);                     // Простое решение
      break;                                    // Выход из функции
      default:break;        // Другие варианты  // Выход из функции
}                        
}
}
 
how does the indicator save the history of values to a file (and load it later)? are there any ready-made solutions?
 
eddy:
How can the indicator save the value history to a file (and load it later)? Are there any ready-made solutions?
There certainly are. From those who once "prepared" them
 
Thanks cap, I'm looking for solutions, not just asking.
 
Pokrov:

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.

 
AlexeyVik:

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.

 
Pokrov:

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.).