defining what 'current chart' means
I can not guarantee to have viewed the chart previously.
How do I control the data so I can get say 5000 bars?
- The chart (pair and timeframe) the script/EA/indicator is running on.
- if iBars is zero Test GetLastError for ERR_HISTORY_WILL_UPDATED, then wait 15 seconds and retry iBars.
- Download history/adjust max bars on chart/max bars in history.
- The chart (pair and timeframe) the script/EA/indicator is running on.
- if iBars is zero Test GetLastError for ERR_HISTORY_WILL_UPDATED, then wait 15 seconds and retry iBars.
- Download history/adjust max bars on chart/max bars in history.
Cool, thanks for the response WHRoeder :)
Point 1 : (the chart that the script is running on) might be where I'm confused.
I've attached the EA to say a GBPUSD M5 chart, but the iBars call is using say EURUSD M15. It may have a number of other symbols as well. Which of these would be considered the current chart? I'm probably doing this wrong, but it is inherited legacy code and I've had to catch it.
Point 2 : I'm always getting something back, for all ticker symbols, the amount varies but it is frequently 2. Which I'm pretty sure is not right.
Point 3: Ahh... good idea, I've checked and they were set to 100000 and 250000, which should do for all intents and purposes.
As I say, I'm probably doing something wrong in the way I'm doing it. What I need to do is get the last 5000 ticks, perhaps this iBars thing is not actually connected to getting the last 5000 ticks for a symbol?
Does that help at all?
Cheers,
Beefy
Point 1 : (the chart that the script is running on) might be where I'm confused.
I've attached the EA to say a GBPUSD M5 chart, but the iBars call is using say EURUSD M15. It may have a number of other symbols as well. Which of these would be considered the current chart? I'm probably doing this wrong, but it is inherited legacy code and I've had to catch it.
Point 2 : I'm always getting something back, for all ticker symbols, the amount varies but it is frequently 2. Which I'm pretty sure is not right.
As I say, I'm probably doing something wrong in the way I'm doing it. What I need to do is get the last 5000 ticks, perhaps this iBars thing is not actually connected to getting the last 5000 ticks for a symbol?
- If you call iBars(NULL,0) you get the count for the current chart. That is the GBPUSD M5 in your example. If you specify the arguments you get that chart, not the current chart.
- Post your code - no mind readers here.
- Mq4 does not store ticks, you can only get OHLC per bar.
- If you call iBars(NULL,0) you get the count for the current chart. That is the GBPUSD M5 in your example. If you specify the arguments you get that chart, not the current chart.
- Post your code - no mind readers here.
- Mq4 does not store ticks, you can only get OHLC per bar.
Thank you again WHRoeder :)
Point 1 : It is the control of that other chart (the EURUSD.m15 one) that is confusing me, because I'm not getting the iBars return value I expected
Point 2 : Sorry, should have posted it at the start, it is a snippet because the code base is a bit unweildy :
// the symbol is a value populated from a table of known good ticker symbols, mPeriod is an array of minute periods known to be acceptable PERIOD_M5 etc
// nothing is done to condition the iBars call before this, so if it has a dependency on other parameters being set or functions being called
// then that is probably where the fault is.
int bar = iBars( symbol, mPeriod[period] ); // returns 1504, 2600 etc for some Tickers (#VZ) and 3 or 8 for some others (EURUSD)
for( int iBar=startBar; iBar >=0; iBar-- ) {
// it is this part that is only looping a few times because the iBars return is so small
saveHistoryBar( id, symbol, period, iBar );
}
where saveHistoryBar is basically:
double o = iOpen( symbol, mPeriod[period], iBar );
double h = iHigh( symbol, mPeriod[period], iBar );
double l = iLow( symbol, mPeriod[period], iBar );
double c = iClose( symbol, mPeriod[period], iBar );
double v = iVolume( symbol, mPeriod[period], iBar );
datetime t = iTime( symbol, mPeriod[period], iBar );
followed by an SQL insert. So that at least matches with your third point :)
The code does work, for some tickers, but it never returns huge numbers for iBars, so something is not setting the chart bars correctly
I really appreciate the time you are taking to look at this, it is a great help to have another brain look at the problem.
Beefy
In the following post
http://www.metatrader4.com/forum/12045/page2
Someone asked the same question in 2009, but did not publish the answer (if they ever got one). So other people have hit this same problem.
Any ideas at all?
Cheers,
Beefy
In the following post
http://www.metatrader4.com/forum/12045/page2
int bar = iBars( symbol, mPeriod[period] ); // returns 1504, 2600 etc for some Tickers (#VZ) // and 3 or 8 for some others (EURUSD)No mind-readers here. Print the values of your variables to find out what you are doing.
int bar = iBars( symbol, mPeriod[period] ); print("iBars('", symbol, "',", mPeriod[period], ")=",bar, " (period=", period, ")");
// the symbol is a value populated from a table of known good ticker symbols, mPeriod is an array of minute periods known to be acceptable PERIOD_M5 etc // nothing is done to condition the iBars call before this, so if it has a dependency on other parameters being set or functions being called // then that is probably where the fault is. int bar = iBars( symbol, mPeriod[period] ); // returns 1504, 2600 etc for some Tickers (#VZ) and 3 or 8 for some others (EURUSD) for( int iBar=startBar; iBar >=0; iBar-- ) { // it is this part that is only looping a few times because the iBars return is so small saveHistoryBar( id, symbol, period, iBar ); } where saveHistoryBar is basically: double o = iOpen( symbol, mPeriod[period], iBar ); double h = iHigh( symbol, mPeriod[period], iBar ); double l = iLow( symbol, mPeriod[period], iBar ); double c = iClose( symbol, mPeriod[period], iBar ); double v = iVolume( symbol, mPeriod[period], iBar ); datetime t = iTime( symbol, mPeriod[period], iBar ); followed by an SQL insert
No mind-readers here. Print the values of your variables to find out what you are doing.
Hello All,
Thanks to everyone for helping me with this, it really helps !
symbol : EURUSD period 43200 iBars : 267
symbol : #HD period 43200 iBars : 1
symbol : #VZ period 43200 iBars : 1
symbol : AUDUSD period 43200 iBars : 267
symbol : EURAUD period 43200 iBars : 172
symbol : EURGBP period 43200 iBars : 267
symbol : EURJPY period 43200 iBars : 267
symbol : GBPJPY period 43200 iBars : 150
symbol : GBPUSD period 43200 iBars : 267
symbol : GOLD period 43200 iBars : 1
symbol : SILVER period 43200 iBars : 1
symbol : USDJPY period 43200 iBars : 267
Is an example of the returns I'm getting from the iBars function.
Does it tell anyone anything about what I should look at next?
Thanks,
Beefy
edit :
I guess if the difference is caused by the tickers having in some sense been "viewed" in a chart, then I guess the question distils to how to make the charts appear as though they are being viewed from a script....
Hello All,
Thanks to everyone for helping me with this, it really helps !
symbol : EURUSD period 43200 iBars : 267
symbol : #HD period 43200 iBars : 1
symbol : #VZ period 43200 iBars : 1
symbol : AUDUSD period 43200 iBars : 267
symbol : EURAUD period 43200 iBars : 172
symbol : EURGBP period 43200 iBars : 267
symbol : EURJPY period 43200 iBars : 267
symbol : GBPJPY period 43200 iBars : 150
symbol : GBPUSD period 43200 iBars : 267
symbol : GOLD period 43200 iBars : 1
symbol : SILVER period 43200 iBars : 1
symbol : USDJPY period 43200 iBars : 267
Is an example of the returns I'm getting from the iBars function.
Does it tell anyone anything about what I should look at next?
Thanks,
Beefy
edit :
I guess if the difference is caused by the tickers having in some sense been "viewed" in a chart, then I guess the question distils to how to make the charts appear as though they are being viewed from a script....
Update : The solution was to ensure the charts loaded, unzoomed, and scrolled into place, as well as checking that all bars from 0 to iBars are returning non-zero for iOpen, before starting the data collection. This process appears to force the load of the rrght data.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there,
I was wondering the if the community could help me out in respect to defining what 'current chart' means in https://docs.mql4.com/series/iBars.
We have the following in our code:
int bar = iBars(symbol, PERIOD_M5);
What we don't understand:
When we loop over the symbol set, we get a different number of bars, some are reasonable (in the thousands) and some are unreasonable (3 or so). I've read that it is apparently related to whether a chart has been viewed before, but this is a script that needs to be able to get data for many combinations of symbols and periods, I can not guarantee to have viewed the chart previously.
How do I control the data so I can get say 5000 bars? My instinct is that this is something to do with controlling the definition of the current chart (something iBars appears to do automatically when called with a symbol name) but I can't pin it down on google
It's driving us nuts over here, so a huge Thank You to anyone that helps !
Beefy