Any idea hot to add a delay in tester autoconfiguration - page 2

 

Thanks guys, I think I see a way to make this work for me now. If I use iOpen() calls then I need to trap for error 4066 and sleep while giving the server time to update the memory-resident hst data before attempting to call iOpen() again. Thanks for all your help.

 

Do you guys think putting the following code snippet in my init file will serve well enough to call the history data from the server for all timeframes on the related Symbol()?

   // Query the hst files to ensure the data are being accessed by the server
   int i,j,ServerSyncTimeFrame,sleep_seconds=30;
   string CurrentSymbol=Symbol();
   
   for(i=1;i<=9;i++)
      { // i looping for M1-MN1 History Files
      switch(i)
         {
         case 1   :  ServerSyncTimeFrame=1;  break; // Synchronize M1 Timeframe data with the server
         case 2   :  ServerSyncTimeFrame=5;  break; // Synchronize M5 Timeframe data with the server
         case 3   :  ServerSyncTimeFrame=15;  break; // Synchronize M15 Timeframe data with the server
         case 4   :  ServerSyncTimeFrame=30;  break; // Synchronize M30 Timeframe data with the server
         case 5   :  ServerSyncTimeFrame=60;  break; // Synchronize M60 Timeframe data with the server
         case 6   :  ServerSyncTimeFrame=240;  break; // Synchronize M240 Timeframe data with the server
         case 7   :  ServerSyncTimeFrame=1440;  break; // Synchronize M1440 Timeframe data with the server
         case 8   :  ServerSyncTimeFrame=10080;  break; // Synchronize M10080 Timeframe data with the server
         case 9   :  ServerSyncTimeFrame=43200;  break; // Synchronize M43200 Timeframe data with the server
         default  :  Print("Error encountered in the SWITCH routine for setting the timeframe for server data synchronization"); return(0);// The expression did not generate a case value
         }
      
      j=0; // initialize the while loop counter
      while(j<10 && (iClose(CurrentSymbol,ServerSyncTimeFrame,2)==0 || GetLastError()==4066)) // call the iClose() function with a shift of 2 to ensure we sample the timeseries in a likely unsynchronized span
         {
         j++; // increment the while loop counter
         Print("Sync cycle ",j,": Sleeping for ",sleep_seconds," seconds to let the server synchronize with requested date for Period M",ServerSyncTimeFrame);
         Sleep(sleep_seconds*1000); // sleep to give the server time to update the local hst file
         }
      if(j==10)
         {
         Print("Failed to synchronize the hst data with the server after ",j," cycles and ",j*sleep_seconds," seconds");
         return(0);
         }
      }

By putting it in init() does this mean I don't have to be worried about the iClose/iOpen/etc calls ever generating a time-synch error later on in the start() routine? The timeframes are all being perpetually updated by the terminal because the iClose() call was made once already during init()?

 

Firstly, it might be a good idea to download M1 only and build all other time-frames from it (with your automated tool) to avoid 'unmatched data error' while testing.

Secondly, I was under the impression that 'forcing' bars to download with this method doesn't work. I don't remember how I reached this conclusion, it was a long time ago. I have searched and the only relevant threads I can come up with are these: https://www.mql5.com/en/forum/103958, https://www.mql5.com/en/forum/123755.

Anyway I hope this does work... Let us know. The code seems fine btw.

 
kar:
When running tester in auto configuration mode, tester starts very quickly and even the account is not activated yet. It takes few seconds for an account to activate in the mean time tester has already performed some testing which generate in valid results. Does any one has idea how to add the delay in tester. Or does any one know why the results of tester using manual (starting the tester manually) is different than the ones which are obtained using auto config for the tester. Please help. Thanks.

in the meantime the only way i managed to do this, is by using WINAPI
 
gordon:

Firstly, it might be a good idea to download M1 only and build all other time-frames from it (with your automated tool) to avoid 'unmatched data error' while testing.

Secondly, I was under the impression that 'forcing' bars to download with this method doesn't work. I don't remember how I reached this conclusion, it was a long time ago. I have searched and the only relevant threads I can come up with are these: https://www.mql5.com/en/forum/103958, https://www.mql5.com/en/forum/123755.

Anyway I hope this does work... Let us know. The code seems fine btw.


That's my plan, was just making the generic case that is applicable to all standard timeframes.

It works by the way, but only pulls 2048 bars (if that many are available) for each timeframe.

This is the code I use to programmatically refresh the M1 chart (which after refreshing I will then period convert and fileflush all period data including the M1 for subsequent file transfers to my auto-optimizers):
   int sleep_seconds=5,CurrentPeriod=Period();
   string CurrentSymbol=Symbol();
   
   int hwnd;
   if(hwnd==0)
      {
      hwnd=WindowHandle(CurrentSymbol,CurrentPeriod); // refresh the current chart timeframe for the current chart symbol
      if(hwnd!=0) Print("M",CurrentPeriod," Chart for ",CurrentSymbol," detected.");
      }
   //---- refresh window
   if(hwnd!=0)
      {
      PostMessageA(hwnd,WM_COMMAND,33324,0);
      Print("Refreshing M",CurrentPeriod," Chart for ",CurrentSymbol,": Sleeping for ",MathMax(sleep_seconds,30)," seconds.");
      Sleep(MathMax(sleep_seconds*1000,30000)); // sleep to give the server time to refresh the current chart
      }

When I do that trick of making a dummy time-zero (1970) candle in the hst files then this code in my init pulls up to 65,560 bars from the server (if available).

Thanks again for all the assistance and pointers :)

 
1005phillip:

Do you guys think putting the following code snippet in my init file will serve well enough to call the history data from the server for all timeframes on the related Symbol()?

By putting it in init() does this mean I don't have to be worried about the iClose/iOpen/etc calls ever generating a time-synch error later on in the start() routine? The timeframes are all being perpetually updated by the terminal because the iClose() call was made once already during init()?


BTW, for the record I can confirm that once you make an iClose() call in the init routine, or elsewhere, provided the calling EA/chart remain active (say the chart is M1, but iClose is called on M5) then the M5 data will continue to be updated behind the scene for the duration until the terminal/chart/ea are closed.
 
1005phillip:

BTW, for the record I can confirm that once you make an iClose() call in the init routine, or elsewhere, provided the calling EA/chart remain active (say the chart is M1, but iClose is called on M5) then the M5 data will continue to be updated behind the scene for the duration until the terminal/chart/ea are closed.
Ya, it seems that the moment u call iClose() on a symbol/time-frame, it gets marked in the history center for download (like I described here -> https://www.mql5.com/en/forum/124619/page2#288454). Popov also reported that it only downloads 2048 bars...
 
Hi,

I probe this code.

But I don't use it.

The Sleep(sleep_seconds*1000); function is not runing. Not sleep!


Why?


In the documentation: "The Sleep() function cannot be called from custom indicators since they calculate in the interface thread and may not decelerate it."

What is it?
 

use the "loop" sleep method.


***

 
Chi Yuen Tseung:

use the "loop" sleep method.


***

Please insert the code correctly: when editing a message, press the button     Codeand paste your code into the pop-up window. (The first time I corrected your message)
Reason: