|
CopyRates
Gets the historical series of the MqlRates structure of the specified symbol-period in the specified amount into a matrix or vector. Elements are counted down from the present to the past, which means that the starting position equal to 0 means the current bar.
The data is copied so that the oldest element is placed at the beginning of the matrix/vector. There are three function options.
Access by the initial position and the number of required elements
bool CopyRates(
|
Access by the initial date and the number of required elements
bool CopyRates(
|
Access by the initial and final dates of the required time interval
bool CopyRates(
|
Parameters
symbol
[in] Symbol.
period
[in] Period.
rates_mask
[in] The ENUM_COPY_RATES enumeration combination of flags specifying the type of requested series. When copying to a vector, only one value from the ENUM_COPY_RATES enumeration can be specified, otherwise an error occurs.
start
[in] First copied element index.
count
[in] Number of copied elements.
from
[in] Bar time corresponding to the first element.
to
[in] Bar time corresponding to the last element.
Return Value
Return true if successful, otherwise false in case of an error.
Note
If the interval of the requested data is completely outside the available data on the server, then the function returns false. If the data outside TERMINAL_MAXBARS (maximum number of bars on the chart) is requested, the function also returns false.
When requesting data from an EA or a script, download from the server is initiated if the terminal does not have the appropriate data locally, or construction of the necessary timeseries starts if the data can be constructed from the local history but they are not ready yet. The function returns the amount that will be ready by the time the timeout expires, however the history download continues, and the function returns more data during the next similar request.
When requesting data by the start date and the number of required items, only data whose date is less than (before) or equal to the specified one is returned. The interval is set and considered up to a second. In other words, the opening date of any bar the value is returned for (volume, spread, Open, High, Low, Close or Time) is always equal to or less than the specified one.
When requesting data in a given date range, only data that falls within the requested interval is returned. The interval is set and considered up to a second. In other words, the opening time of any bar the value is returned for (volume, spread, indicator buffer value, Open, High, Low, Close or Time) is always located in the requested interval.
For example, if the current day of the week is Saturday, the function returns 0 when attempting to copy data on the weekly timeframe by setting start_time=Last_Tuesday and stop_time=Last_Friday because the open time on the weekly timeframe always falls on Sunday, but not a single weekly bar falls within the specified range.
If you need to get the value corresponding to the current incomplete bar, then you can use the first call form indicating start_pos=0 and count=1.
The ENUM_COPY_RATES enumeration contains the flags to specify the type of data to be passed to the matrix or array. The flag combination allows getting several series from the history in one request. The order of the rows in the matrix will correspond to the order of the values in the ENUM_COPY_RATES enumeration. In other words, the row with High data will always be higher in the matrix than the row with Low data.
ID |
Value |
Description |
---|---|---|
COPY_RATES_OPEN |
1 |
Open price series |
COPY_RATES_HIGH |
2 |
High price series |
COPY_RATES_LOW |
4 |
Low price series |
COPY_RATES_CLOSE |
8 |
Close price series |
COPY_RATES_TIME |
16 |
Time series (bar open time)
Getting time in float of the vector and the matrix (vectord and matrixf) causes losses of ~100 seconds since float accuracy is severely limited and integers greater than 1<<24 cannot be accurately represented in float. |
COPY_RATES_VOLUME_TICK |
32 |
Tick Volumes |
COPY_RATES_VOLUME_REAL |
64 |
Trade Volumes |
COPY_RATES_SPREAD |
128 |
Spreads |
Combination |
|
|
COPY_RATES_OHLC |
15 |
Open, High, Low and Close series |
COPY_RATES_OHLCT |
31 |
Open, High, Low, Close and Time series |
Data arrangement |
|
|
COPY_RATES_VERTICAL |
32768 |
Series are copied into the matrix along the vertical axis. The received series values will be arranged vertically in the matrix, i.e., the oldest data will be in the first row, while the most recent data will be in the last matrix row.
With default copying, series are added into a matrix along the horizontal axis.
The flag is only applicable when copying to a matrix. |
Example:
//+------------------------------------------------------------------+
|
See also