MQL4 Timeseries and Indicator Data Access

Overview

Functions for accessing timeseries and indicator data. Timeseries arrays are indexed in reverse order: the most recent data (current bar) is at index 0, and older data follows.

Data Handling

  • **Recommended Array Type:** Dynamic arrays for copying timeseries and indicator data.
  • **Performance Optimization:** For frequent data access (e.g., in OnTick() or OnCalculate()), use statically allocated arrays to avoid dynamic array memory allocation overhead.
  • **Indexing Direction:** Be mindful of the reverse indexing (series direction) in timeseries arrays. Use ArraySetAsSeries(array, true) to enable this behavior.
  • Asynchronous Access

  • Access to indicator and timeseries data is asynchronous.
  • If data is not ready, Copy...() functions return an error immediately.
  • In Expert Advisors and scripts, multiple attempts with small pauses are made to retrieve data, allowing time for download or calculation.
  • When requesting data from other charts (different symbol/timeframe), if the chart is not open, ERR_HISTORY_WILL_UPDATED (4066) may be returned, requiring a re-request.
  • Key Functions

    | Function | Action | | -------------------- | ---------------------------------------------------------------------- | | SeriesInfoInteger | Returns information about historical data state. | | RefreshRates | Refreshes data in pre-defined variables and series arrays. | | CopyRates | Gets Rates structure history data for a specified symbol and period. | | CopyTime | Gets bar opening time history data. | | CopyOpen | Gets bar opening price history data. | | CopyHigh | Gets maximal bar price history data. | | CopyLow | Gets minimal bar price history data. | | CopyClose | Gets bar closing price history data. | | CopyTickVolume | Gets tick volume history data. | | Bars | Returns the total number of bars in history for a symbol/period. | | iBars | Returns the number of bars on the specified chart. | | iBarShift | Returns the index of the bar covering a specified time. | | iClose | Returns Close price for a specified bar, symbol, and timeframe. | | iHigh | Returns High price for a specified bar, symbol, and timeframe. | | iHighest | Returns the shift of the maximum value over a specific number of bars. | | iLow | Returns Low price for a specified bar, symbol, and timeframe. | | iLowest | Returns the shift of the lowest value over a specific number of bars. | | iOpen | Returns Open price for a specified bar, symbol, and timeframe. | | iTime | Returns time value for a specified bar, symbol, and timeframe. | | iVolume | Returns Tick Volume for a specified bar, symbol, and timeframe. |

    Array Indexing

  • ArraySetAsSeries(array, true) sets an array to behave like a timeseries (reverse indexing).
  • ArraySetAsSeries(array, false) sets an array to standard indexing (forward indexing).
  • Physical storage order of array elements remains the same; only the indexing direction changes.
  • Related Functions

  • ArrayIsDynamic()
  • ArrayGetAsSeries()
  • ArraySetAsSeries()
  • ArrayIsSeries()
  • SymbolInfoSessionTrade()