MQL5 CopyTicks()
Copies ticks of a symbol into an array of MqlTick structures, from a time onwards or the most recent ones. 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.
The page says the first call for a symbol starts synchronising the terminal's stored ticks with the trade server, and ticks the terminal lacks are downloaded.
Signature
The form of the call on the vendor's page, with the vendor's comments taken out.
int CopyTicks( string symbol_name, MqlTick& ticks_array[], uint flags=COPY_TICKS_ALL, ulong from=0, uint count=0 )
Arguments
| Name | Type | Description |
|---|---|---|
| symbol_namerequired | string | The symbol. |
| ticks_arrayrequired | MqlTick&[] | The array of MqlTick that receives the ticks. |
| 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 | ulong | The time to copy from, in milliseconds since 1 January 1970. With 0, the most recent ticks are returned, as many as count asks for. Default: 0. |
| count | uint | How many ticks to copy. The page says that when neither from nor count is given, the most recent ticks are returned, up to 2,000 of them. Default: 0. |
Return value
- Type
- int
- What comes back
- The number of ticks copied, or -1 on an error.
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[];
int copied=CopyTicks(_Symbol,ticks,COPY_TICKS_INFO,0,100);
if(copied<0)
PrintFormat("CopyTicks error %d",GetLastError());
else if(copied>0)
PrintFormat("%d ticks, newest bid %.5f",copied,ticks[copied-1].bid);
}