int year = TimeYear(Time[i]); if (year > 1970) {
because Time[i] will always use the times of the current symbol and timeframe, the one of the chart where the script is running on.
You want to export many different symbols and for each one you can only access them with iTime() instead, like you already do it one line below that.
Also you should use iBars() instead of Bars for your loop for getting the numbers of bars in the other symbols because Bars will always only give you the number of bars in the current chart and this is absolutely not relevant when exporting a different symbol/timeframe, each of them have a completely different number of bars available in the downloaded history.
You can also use iBarShift() to directly find the starting point for your loop for any given date. It will return the bar index number corresponding to a certain date in a certain symbol and period. This way you do not need to loop over all the older irrelevant bars, check their date and throw them away, you can directly start the loop at 1.1.1970 00:00 or the oldest available bar, nearest to that date.
for(int i=Bars; i>0; i--) { int year = TimeYear(Time[i]); if (year > 1970) {
indexes are zero based: 0, 1, ... Bars-1. You are referring one past the end
- If you are not referencing the current symbols/period then you must use iTime, iBars etc.
wrong:
because Time[i] will always use the times of the current symbol and timeframe, the one of the chart where the script is running on.
You want to export many different symbols and for each one you can only access them with iTime() instead, like you already do it one line below that.
Also you should use iBars() instead of Bars for your loop for getting the numbers of bars in the other symbols because Bars will always only give you the number of bars in the current chart and this is absolutely not relevant when exporting a different symbol/timeframe, each of them have a completely different number of bars available in the downloaded history.
You can also use iBarShift() to directly find the starting point for your loop for any given date. It will return the bar index number corresponding to a certain date in a certain symbol and period. This way you do not need to loop over all the older irrelevant bars, check their date and throw them away, you can directly start the loop at 1.1.1970 00:00 or the oldest available bar, nearest to that date.
Thank you very much 7bit I'm very beginner at mql4 and not accustomed to programming :)
indexes are zero based: 0, 1, ... Bars-1. You are referring one past the end
- If you are not referencing the current symbols/period then you must use iTime, iBars etc.
This code snippet will be usefull for me thanks.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have put a condition on year
still it doesn't take into account, do you see why ?
Full source below: