iBars() weirdness

 
   string p = Symbol();
   string s = p + " " +(string)iBars(p,       PERIOD_M1) + "\n";
   s+= "NZDUSD" + " " +(string)iBars("NZDUSD",PERIOD_M1) + "\n";
   s+= Symbol() + " " +(string)iBars(Symbol(),PERIOD_M1) + "\n";
   Comment(s);


ok, so thats the code. The output is:

NZDUSD 0
NZDUSD 0
NZDUSD 3365539 

further investigation shows that StringCompare thinks p and Symbol() and "NZDUSD" are identical, so why does iBars() call return 0?

other timeseries access functions like iClose return correct values for all three.


Does anyone know what is going on with the iBars() function?

 

Did you consider perhaps that on the first call, maybe not all data was fully loaded for the chart and that it had to synchronise the data, and by the third call, it was then fully available?

void OnStart() {
   string p = Symbol();
   string s = p + " " +(string)iBars(p,       PERIOD_M1) + "\n";
   s+= "NZDUSD" + " " +(string)iBars("NZDUSD",PERIOD_M1) + "\n";
   s+= Symbol() + " " +(string)iBars(Symbol(),PERIOD_M1) + "\n";
   Print(s);
};
2023.02.06 00:34:32.728	TestBar (NZDUSD,M1)	NZDUSD 1390905
2023.02.06 00:34:32.728	TestBar (NZDUSD,M1)	NZDUSD 1390905
2023.02.06 00:34:32.728	TestBar (NZDUSD,M1)	NZDUSD 1390905
Also read the following ... Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
 
Fernando Carreiro #:

Did you consider perhaps that on the first call, maybe not all data was fully loaded for the chart and that it had to synchronise the data, and by the third call, it was then fully available?

Also read the following ... Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access

Thanks for the assistance.

Rearranging the calls so that Symbol() is not last, and adding calls to SeriesInfoInteger (which should return the same vals as iBars()

   string p = Symbol();
   string s = p + " " +(string)iBars(p,PERIOD_M1) + "\n";
   s+= Symbol() + " " +(string)iBars(Symbol(),PERIOD_M1) + "\n";
   s+= "EURUSD" + " " +(string)iBars("EURUSD",PERIOD_M1) + "\n";
   s+="SeriesInfoInteger()\n";
   s+= Symbol() + " " +(string)SeriesInfoInteger(Symbol(),PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   s+= p + " " +(string)SeriesInfoInteger(p,PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   s+= "EURUSD" + " " +(string)SeriesInfoInteger("EURUSD",PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   Print(s);

yields

2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     NZDUSD 0
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     NZDUSD 3365571
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     EURUSD 0
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     SeriesInfoInteger()
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     NZDUSD 3365571
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     NZDUSD 0
2023.02.06 13:46:23.517 II_P&F5 (NZDUSD,H1)     EURUSD 0
 

This

iBarShift(p,PERIOD_M1,SeriesInfoInteger(p,PERIOD_M1,SERIES_FIRSTDATE));

returns the correct bar shift (ie count-1).

its an ugly kludge, but it works, so I can get back to work.

 
el_looto #: This ... returns the correct bar shift (ie count-1). its an ugly kludge, but it works, so I can get back to work.

Don't use a kludge! You should figure out the cause first and resolve it, or else it will come back to "haunt" you.

It is working just fine on my end (see next post), so something is different on your setup.

What build of MetaTrader 5 is it?

 
el_looto #: Thanks for the assistance. Rearranging the calls so that Symbol() is not last, and adding calls to SeriesInfoInteger (which should return the same vals as iBars(). yields
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     NZDUSD 7675402
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     NZDUSD 7675402
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     EURUSD 8655307
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     SeriesInfoInteger()
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     NZDUSD 7675403
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     NZDUSD 7675403
2023.02.06 01:36:02.069 TestBar (NZDUSD,M1)     EURUSD 8655307
void OnStart() {
   string p = Symbol();
   string s = p + " " +(string)iBars(p,PERIOD_M1) + "\n";
   s+= Symbol() + " " +(string)iBars(Symbol(),PERIOD_M1) + "\n";
   s+= "EURUSD" + " " +(string)iBars("EURUSD",PERIOD_M1) + "\n";
   s+="SeriesInfoInteger()\n";
   s+= Symbol() + " " +(string)SeriesInfoInteger(Symbol(),PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   s+= p + " " +(string)SeriesInfoInteger(p,PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   s+= "EURUSD" + " " +(string)SeriesInfoInteger("EURUSD",PERIOD_M1,SERIES_BARS_COUNT) + "\n";
   Print(s);
};


 
Fernando Carreiro #:

Don't use a kludge! You should figure out the cause first and resolve it, or else it will come back to "haunt" you.

It is working just fine on my end (see next post), so something is different on your setup.

What build of MetaTrader 5 is it?

MT5 v5.00 build 3550

As far as I can tell, there is literally no difference between the calls to iBars() made by variable, hardcoding, or Symbol().

Ive restarted my machine, the client and the chart. Im pretty sure the call was working from a variable a few days ago, but Ive rearranged the code a bit since then and now need to move on to making calls to charts the indi isnt sitting on (thus Symbol() is itself not useable).

Whats extra weird is that calls to iBars() with my custom symbol name as a variable work just fine ie

iBars(m_custom_symbol_name,PERIOD_M1);


returns the correct bar count of the custom point and figure charts Ive created.

Reason: