MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading Language Documentation

Interview with Rogério Figurelli (ATC 2012) Interview with RogĂ©rio Figurelli (ATC 2012) Subscribe to signal
AAABachelorBroker1
12.06%, 5 603.08 USD
Screenshot
EURJPY., H1
Real
MT5 Money ManagerMT5 Money Manager Try product
MT5 Money Manager
Author: Dantepuma
s-LastPinkEventDate Script
s-LastPinkEventDate
Author: FinGeR

Bars

Returns the number of bars count in the history for a specified symbol and period. There are 2 variants of functions calls.

Request all of the history bars

int  Bars(
   string           symbol_name,     // symbol name
   ENUM_TIMEFRAMES  timeframe        // period
   );

Request the history bars for the selected time interval

int  Bars(
   string           symbol_name,     // symbol name
   ENUM_TIMEFRAMES  timeframe,       // period
   datetime         start_time,      // start date and time
   datetime         stop_time        // end date and time
   );

Parameters

symbol_name

[in]  Symbol name.

timeframe

[in]  Period.

start_time

[in]  Bar time corresponding to the first element.

stop_time

[in]  Bar time corresponding to the last element.

Return Value

If the start_time and stop_time parameters are defined, the function returns the number of bars in the specified time interval, otherwise it returns the total number of bars.

Note

If data for the timeseries with specified parameters are not formed in the terminal by the time of the Bars() function call, or data of the timeseries are not synchronized with a trade server by the moment of the function call, the function returns a zero value.

Sample:

   int bars=Bars(_Symbol,_Period);
   if(bars>0)
     {
      Print("Number of bars in the terminal history for the symbol-period at the moment = ",bars);
     }
   else  //no available bars
     {
      //--- data on the symbol might be not synchronized with data on the server
      bool synchronized=false;
      //--- loop counter
      int attempts=0;
      // make 5 attempts to wait for synchronization
      while(attempts<5)
        {
         if(SeriesInfoInteger(Symbol(),0,SERIES_SYNCHRONIZED))
           {
            //--- synchronization done, exit
            synchronized=true;
            break;
           }
         //--- increase the counter
         attempts++;
         //--- wait 10 milliseconds till the nest iteration
         Sleep(10);
        }
      //--- exit the loop after synchronization
      if(synchronized)
        {
         Print("Number of bars in the terminal history for the symbol-period at the moment = ",bars);
         Print("The first date in the terminal history for the symbol-period at the moment = ",
               (datetime)SeriesInfoInteger(Symbol(),0,SERIES_FIRSTDATE));
         Print("The first date in the history for the symbol on the server = ",
               (datetime)SeriesInfoInteger(Symbol(),0,SERIES_SERVER_FIRSTDATE));
        }
      //--- synchronization of data didn't happen
      else
        {
         Print("Failed to get number of bars for ",_Symbol);
        }
     }

See also

Event Processing Functions


Updated: 2012.09.05