hello all,
I start working on CopyRates, I have some question about this function,
first, I try to run this function in a script but the value I get for each day(for example the last 7 days) are just the same for one symbol, can you help me with it?
and second I run it in a script, because there are several symbols in my market watch that I want to get their close price, can I do it in just one script?
this is my code, I really appreciate if you help
Your main issue is the way you are trying to use time in this scenario. You are attempting to get rates from the beginning of today to seven days into the future. Even if you were to subtract the seconds this would still cause you errors due to the markets being closed over the weekends. You could use iTime to get the start and end times based on the number of bars, but a much better solution is to use the PERIOD_D1 timeframe and simply specify the number of bars.
#property script_show_inputs //--- input parameters input int inp_num_days = 7; //Number of days //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { MqlRates rates[]; ArraySetAsSeries(rates, true); int total = CopyRates(_Symbol, PERIOD_D1, 1, inp_num_days, rates); for(int i=0; i<total; i++){ printf("The close on %s was %s", TimeToString(rates[i].time, TIME_DATE), DoubleToString(rates[i].close, _Digits) ); } }
Your main issue is the way you are trying to use time in this scenario. You are attempting to get rates from the beginning of today to seven days into the future. Even if you were to subtract the seconds this would still cause you errors due to the markets being closed over the weekends. You could use iTime to get the start and end times based on the number of bars, but a much better solution is to use the PERIOD_D1 timeframe and simply specify the number of bars.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello all,
I start working on CopyRates, I have some question about this function,
first, I try to run this function in a script but the value I get for each day(for example the last 7 days) are just the same for one symbol, can you help me with it?
and second I run it in a script, because there are several symbols in my market watch that I want to get their close price, can I do it in just one script?
this is my code, I really appreciate if you help