Using the Sleep() Function in MQL5 vs MQL4

 
I'm doing an EA translation from MQL4 to MQL5 and need advice of whether or not to use the Sleep() Function as it was written for MQL4. I've done some testing by commenting out the Sleep() Function entirely in my MQL5 code and everything appears to work fine. My question for advice is:
Should I completely eliminate the Sleep() Function entirely in my MQL5 code?
Should I modify the 2000 millisecond wait time to some other number?
Should I use some other method for the wait time if a wait is even needed?

The Procedures that are called immediately before calling the Sleep() Functions are used to write data into .csv files.

Thank you for any suggestions!

input int FrequencyUpdate = 60;

datetime UpdateTime = 0;

void OnTick()
{
   if ( UpdateTime <= StringToTime( TimeToString( TimeCurrent(), TIME_SECONDS ) ) )
   {
      UpdateTime = StringToTime( TimeToString( TimeCurrent() + FrequencyUpdate, TIME_SECONDS ) );
      ROpen = true;
   }
   if ( ROpen == true )
   {
      if ( LoadM1 )
      {
         LoadingM1();
         Sleep( 2000 );
      }
      if ( LoadM5 )
      {
         LoadingM5();
         Sleep( 2000 );
      }
      if ( LoadM15 )
      {
         LoadingM15();
         Sleep( 2000 );
      }
      if ( LoadM30 )
      {
         LoadingM30();
         Sleep( 2000 );
      }
      if ( LoadH1 )
      {
         LoadingH1();
         Sleep( 2000 );
      }
      if ( LoadH4 )
      {
         LoadingH4();
         Sleep( 2000 );
      }
      if ( LoadD1 )
      {
         LoadingD1();
         Sleep( 2000 );
      }
      if ( LoadW1 )
      {
         LoadingW1();
         Sleep( 2000 );
      }
      if ( LoadMN )
      {
         LoadingMN();
         Sleep( 2000 );
      }
      ROpen = false;
   }
}

 
The Sleep function in the EA is a big evil. If you use this function, it means your code contains an error.
 
Vladimir Karputov:
The Sleep function in the EA is a big evil. If you use this function, it means your code contains an error.

I'm doing this EA translation from code that I did not develop. The original developer gave me the source code and permission to migrate it to MQL5.

I'm not quite sure what you mean by "your code contains an error" because I have all the source code converted to MQL5 and it compiles and runs fine both with and without using the Sleep() Function.

I don't know the reason the original developer used the Sleep() Function. It appeared to me to be waiting 2 seconds for connection to the data server.

By saying it's a "big evil" are you advising to eliminate it from the source code?

 
Frank Jarrett:

I'm doing this EA translation from code that I did not develop. The original developer gave me the source code and permission to migrate it to MQL5.

I'm not quite sure what you mean by "your code contains an error" because I have all the source code converted to MQL5 and it compiles and runs fine both with and without using the Sleep() Function.

I don't know the reason the original developer used the Sleep() Function. It appeared to me to be waiting 2 seconds for connection to the data server.

By saying it's a "big evil" are you advising to eliminate it from the source code?

i found an article about sleep() function here which could be useful to you

To Sleep, or Not to Sleep?
To Sleep, or Not to Sleep?
  • www.mql5.com
During its operations, an Expert Advisor sometimes produces situations in which it must make pauses between operations. This may be caused both by the necessity to meet the requirement of holding a certain interval between repeated requests to the trade server (in case of execution errors) and by waiting for a certain event (for example, for...