MQL5 CopyTicksRange()
Copies the ticks of a symbol between two times into an array of MqlTick structures. The oldest tick copied is at index 0.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
This is an MQL5 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 5 terminal, in a program written in MQL5.
Signature
The form of the call on the vendor's page, with the vendor's comments taken out.
int CopyTicksRange( const string symbol_name, MqlTick& ticks_array[], uint flags=COPY_TICKS_ALL, ulong from_msc=0, ulong to_msc=0 )
Arguments
| Name | Type | Description |
|---|---|---|
| symbol_namerequired | const string | The symbol. |
| ticks_arrayrequired | MqlTick&[] | The array of MqlTick that receives the ticks, static or dynamic. The page says a static array that is too small is filled as far as it goes and the error ERR_HISTORY_SMALL_BUFFER, 4407, is raised. |
| flags | uint | Which ticks to copy: COPY_TICKS_INFO for ticks that change the bid or ask, COPY_TICKS_TRADE for ticks that change the last price or volume, COPY_TICKS_ALL for all of them. Default: COPY_TICKS_ALL. |
| from_msc | ulong | The start of the range, in milliseconds since 1 January 1970. Ticks at or after this time are copied. Left out, copying starts from the beginning of the history. Default: 0. |
| to_msc | ulong | The end of the range, in milliseconds since 1 January 1970. Ticks at or before this time are copied. Left out, copying runs to the end of the history. Default: 0. |
Return value
- Type
- int
- What comes back
- The number of ticks copied, or -1 on an error. On failure the page points to GetLastError() for the reason.
Sample
Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.
void OnStart()
{
MqlTick ticks[];
ulong from=(ulong)D'2026.01.08 12:00'*1000;
ulong to =(ulong)D'2026.01.08 13:00'*1000;
int copied=CopyTicksRange(_Symbol,ticks,COPY_TICKS_ALL,from,to);
PrintFormat("%d ticks, error %d",copied,GetLastError());
}