Yes, that is correct. MT4 only generates approximately 1000 bars back (if available), from the date you selected as the starting date. That is why you should always check Bars, Bars() or iBars() to know how many are available.
Also, when using multi-time-frame, MT4 will use the data in the HST files (for data not in the current time-frame) instead of the data in the FXT files.
To work around this issue, here are two possible approaches:
- Set a start date well before the date you need, but then add a time constraint in your code, to only start processing from the date you originally intended. This will only work if the necessary data is available from the broker and/or in the HST files.
- Alternatively, generate the test data (FXT and HST files) using 3rd party tools such as TickStory or Birt's Tickdate Suite.
Yes, that is correct. MT4 only generates approximately 1000 bars back (if available), from the date you selected as the starting date. That is why you should always check Bars, Bars() or iBars() to know how many are available.
Also, when using multi-time-frame, MT4 will use the data in the HST files (for data not in the current time-frame) instead of the data in the FXT files.
To work around this issue, here are two possible approaches:
- Set a start date well before the date you need, but then add a time constraint in your code, to only start processing from the date you originally intended. This will only work if the necessary data is available from the broker and/or in the HST files.
- Alternatively, generate the test data (FXT and HST files) using 3rd party tools such as TickStory or Birt's Tickdate Suite.
Yes, I had thought of option 1 as well. It's not pretty but it gets the job done. Option 2 is not really an option at the moment because I want to use specific data from my own broker. Would be nice to know how to generate those data files for myself. But that's a project for somewhere in the future. One challenge at a time.
FMIC, thanks for the info!
Please note that tick data produced by MT4 for the FXT files is not "real". The tick data is "emulated" based on the M1 data. So, unless your code is using only OHLC prices of M1 or higher, you are not really using broker tick data. Using 3rd party generated tick data is actually much more "real" than that produced by MT4, even if it is from a different source. Also, many brokers use the same liquidity providers, so tick data by one broker can easily be substituted by tick data by another broker with only minor differences.
Please note that tick data produced by MT4 for the FXT files is not "real". The tick data is "emulated" based on the M1 data. So, unless your code is using only OHLC prices of M1 or higher, you are not really using broker tick data. Using 3rd party generated tick data is actually much more "real" than that produced by MT4, even if it is from a different source. Also, many brokers use the same liquidity providers, so tick data by one broker can easily be substituted by tick data by another broker with only minor differences.
OK!
I am trying to build an indicator according to the following:
If a certain condition is met on a Daily candle -> Draw indicator using candles in the 1hour chart as reference (within that Day).
In order to link the daily candle with the set of candles from the 1H chart in a way that I can operate with these candles, I thought of using CopyRates(_,_,Time,24,_), where Time = Time[i] of Daily candle.
By running Comment(Time[i]) however, I noticed that the open times of the daily are always at 00:00 while in the 1H chart, the first hour of the daily period alternates between 00:00 and 1:00am.
Surely I'll get an error whenever the 00:00 candle in the 1H doesn't exist, right?
Why is that? Why, in the 1H chart, does the day sometimes start at 00:00, sometimes at 1:00? In other words, within a period separator, sometimes there will be 23 candles, sometimes 24.
And do you have another idea how to link the daily chart to the hourly one besides Time[]?
Thanks in advance,
I am trying to build an indicator according to the following:
If a certain condition is met on a Daily candle -> Draw indicator using candles in the 1hour chart as reference (within that Day).
In order to link the daily candle with the set of candles from the 1H chart in a way that I can operate with these candles, I thought of using CopyRates(_,_,Time,24,_), where Time = Time[i] of Daily candle.
By running Comment(Time[i]) however, I noticed that the open times of the daily are always at 00:00 while in the 1H chart, the first hour of the daily period alternates between 00:00 and 1:00am.
Surely I'll get an error whenever the 00:00 candle in the 1H doesn't exist, right?
Why is that? Why, in the 1H chart, does the day sometimes start at 00:00, sometimes at 1:00? In other words, within a period separator, sometimes there will be 23 candles, sometimes 24.
And do you have another idea how to link the daily chart to the hourly one besides Time[]?
Thanks in advance,
Sounds like you have missing bars in your data or you're looking at a difference because of daylight saving time. Some brokers also have a short pause every day. My broker pauses for about 5 minutes at the beginning of a new trading-day, which is at 21:05 GMT (during summer time).
Anyway, MT4 does not build time frames from the lowest time frame automatically. It records data for hourly and daily time frames separately. That's why you can get these differences. I record only the minute time frame and then use the PeriodConverter script (which comes with MT4) to create the other time frames. (I will actually start doing it different in the near future because my broker supplies historic data through an API.)
But at the moment you can only work with the data that you have, so that's a bit of a problem. You can use the iBarShift function to find the bar you looking for on the hourly time frame. You can use it with the exact=false mode so that it doesn't give you an error but shifts to the nearest bar. But you have to check which bar you get, because it could be the last bar of the previous day. If that's the case you need to go to the next bar to get the first bar of the day you're looking for. But the opening price of that bar will not match the opening price on the day bar.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I was working on an EA that looks back several days on the 1 minute time frame, and I was getting strange results I didn’t understand. Until I noticed that not all history is available in the strategy tester.
datetime SomeTime = iTime( Symbol() , PERIOD_M1 , 1001 );
int rc = GetLastError();
If I run the above code in the strategy tester, then I get an error 4051 (invalid parameter) on the first tick that passes. It doesn’t matter what day you start on. And yes, I’ve checked that there is enough data in the history file. If I use Time[1001] I don’t get a warning but the result is zero.
So it seems that when MT prepares historic data for testing, it only selects a 1000 bars before the starting date and nothing more. Or am I missing something?