MQL4 - automated forex trading   /  

Documentation

MQL4 Reference  Window functions  RefreshRates

 
Learn possibilities of the new MQL5
Want to study a new language?
bool RefreshRates( )
Refreshing of data in pre-defined variables and series arrays. This function is used when expert advisor has been calculating for a long time and needs data refreshing. Returns TRUE if data are refreshed, otherwise returns FALSE. The only reason for data cannot be refreshed is that they are the current data of the client terminal.

Experts and scripts operate with their own copy of history data. Data of the current symbol are copied at the first launch of the expert or script. At each subsequent launch of the expert (remember that script is executed only once and does not depend on incoming ticks), the initial copy will be updated. One or more new ticks can income while the expert or script is operating, and data can become out of date.
Sample:
   int ticket;
   while(true)
     {
      ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);
      if(ticket<=0)
        {
         int error=GetLastError();
         //---- not enough money
         if(error==134) break;
         //---- 10 seconds wait
         Sleep(10000);
         //---- refresh price data
         RefreshRates();
         break;
        }
      else
        {
         OrderSelect(ticket,SELECT_BY_TICKET);
         OrderPrint();
         break;
        }
     }