What is CopyRates?
Imagine you have a big box of toy cars, and each car represents a piece of information about how much a toy car costs at different times. The CopyRates function is like a magic tool that helps you take out a certain number of toy cars from that box, so you can see how their prices changed over time.
How Does It Work?
**Choosing the Box:** First, you need to tell the magic tool which box (or chart) you want to look at. In our case, the box is a specific type of toy car, like a race car or a fire truck. In the world of trading, this means you choose a specific currency pair or stock.
**Picking the Time:** Next, you decide how far back in time you want to look. Do you want to see the prices from today, yesterday, or even a week ago? This is like saying, "I want to see the prices from the last 10 toy cars I played with."
**Getting the Information:** When you use the CopyRates function, it goes into the box and pulls out the toy cars (or price information) you asked for. It gives you a list of prices, along with some other details like when each price was recorded.
Example
Let’s say you want to know how much a toy car cost every hour for the last 5 hours. You would use CopyRates like this:
Tell it the box: "I want to look at the toy car prices."
Say how far back: "Give me the last 5 hours of prices."
Get the prices: The magic tool gives you a list that looks something like this:
`1. Hour 1: $5
- Hour 2: $6
- Hour 3: $5.50
- Hour 4: $7
- Hour 5: $6.50
`
Why is it Useful?
Using CopyRates is helpful because it allows you to see how prices change over time. Just like you might want to know if your toy cars are getting more expensive or cheaper, traders want to know how the prices of stocks or currencies are moving. This helps them make decisions about when to buy or sell.
Summary
CopyRates is like a magic tool that helps you look at prices over time.
You choose which box (or chart) to look at and how far back in time you want to see.
It gives you a list of prices, helping you understand how things are changing.
So, just like you can keep track of your toy cars and their prices, traders use CopyRates to keep track of prices in the market!
The CopyRates function in MQL5 provides a complete set of information for each time period (or candle) that you request. Specifically, it gives you the following details for each period:
**Open Price:** The price at which the period (candle) opened.
**Close Price:** The price at which the period (candle) closed.
**High Price:** The highest price reached during that period.
**Low Price:** The lowest price reached during that period.
**Volume:** The total volume of trades that occurred during that period.
**Time:** The opening time of the period.
Example of What You Get
When you use CopyRates, you get an array of MqlRates structures, where each structure contains all of the above information for a specific time period. Here’s a simple breakdown of what the data looks like:
MqlRates rates[];
if (CopyRates("EURUSD", PERIOD_H1, 0, 5, rates) > 0) {
// Now rates array contains the last 5 hourly candles
for (int i = 0; i < ArraySize(rates); i++) {
Print("Time: ", rates[i].time,
" Open: ", rates[i].open,
" Close: ", rates[i].close,
" High: ", rates[i].high,
" Low: ", rates[i].low,
" Volume: ", rates[i].tick_volume);
}
}