Dear Members,
I would really appreciate if anyone can guide me with this.
I want to retrieve the rates using the copyRates() function between 2 specified timings:
Start Time: currentTime()
End Time: currentTime()-30 minutes.
I found the sample code in the below link, but not sure how to pass the 2 date/time parameters.
https://www.mql5.com/en/docs/series/copyrates
On the page, it mentions
Call by the start and end dates of a required time interval
Thank You.
i your version you count the bars.
you have to enter a variable in datetime formart
as exemple
TimeCurrent() = actual time or start time
TimeCurrent()-xxxxxx you can use as endtime or you use
D`01.01.1970`
Do it exactly as you want. Just pass them.
Documentation |
Your code |
---|---|
int CopyRates( string symbol_name, // symbol name ENUM_TIMEFRAMES timeframe, // period datetime start_time, // start date and time datetime stop_time, // end date and time MqlRates rates_array[] // target array to copy ); |
int copied=CopyRates( Symbol(), // symbol name 0, // Don't hard code constants PERIOD_CURRENT 0, // Start Time: TimeCurrent() 100, // End Time: TimeCurrent() - 30*60 // 30 Min rates // array ); |
That works perfectly. Thank you very much for your time and inputs William Roeder and Amando, really appreciate it.
Now what I'm looking to do is as below:
Normally a candlestick is formed starting from a fixed time for example: A 30 min candle is formed from 0800 to 0830 and the next one is 0830 to 0900. The closing of the candle is onTick()
I would like to create a candle using CopyRates() in the reverse order where the statring point is the CurrentTickTime and the end of the array is CurrentTickTime - 30 minutes. Like a floating candle of the last 30 minutes.
Below is the code I have so far with help from the previous comments.. I will be grateful for any further guidance to achieve what i'm looking to do.
void OnTick() { int Interval = 30; datetime d1=TimeCurrent(); datetime d2=TimeCurrent()-Interval*60; MqlRates rates[]; ArraySetAsSeries(rates,true); int copied=CopyRates( Symbol(), // symbol name PERIOD_CURRENT, // Don't hard code constants PERIOD_CURRENT d1, // Start Time: TimeCurrent() d2, // End Time: TimeCurrent() - 30*60 // 30 Min rates // array ); if(copied>0) { Print("Bars copied: "+copied); string format="open = %G, high = %G, low = %G, close = %G, volume = %d"; string out; int size=fmin(copied,10); for(int i=0;i<size;i++) { out=i+":"+TimeToString(rates[i].time); out=out+" "+StringFormat(format, rates[i].open, rates[i].high, rates[i].low, rates[i].close, rates[i].tick_volume); Print(out); } } else Print("Failed to get history data for the symbol ",Symbol());

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Members,
I would really appreciate if anyone can guide me with this.
I want to retrieve the rates using the copyRates() function between 2 specified timings:
Start Time: currentTime()
End Time: currentTime()-30 minutes.
I found the sample code in the below link, but not sure how to pass the 2 date/time parameters.
https://www.mql5.com/en/docs/series/copyrates
On the page, it mentions
Call by the start and end dates of a required time interval
Thank You.