Bars(_symbol, _period) Problem: It always returns same number of bars.

 

Hello,

I have developed  a robot which uses Bars() function to detect new bars through a simple code which checkss number of bars increases.

The problem is that suddenly, Bars() function does not work properly when the robot is running on the terminal, as it always returns the same number of bars.

The funny thing is that it is ok running the robots in the tester and with the visual option, but not in the terminal for real operations, as I said.

I'm using build 756.



Anyone can help?



Thanks in advance.




Juan

Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
Timeseries and Indicators Access / Bars - Documentation on MQL5
 

What an odd coincidence. I had that exact same problem this morning!

Works fine in backtest, but not in live trading. The number of bars in the chart appears to be constant during live trading - even as new bars are added. Presumably MT5 deletes the old bars as new ones occur - but only during live trading and not in backtest?

This is clearly different to MT4, because this method of counting bars is the same one I use for detecting new bars in MT4 - and it seems to work fine there because the number of bars increases in live trade charts as new bars are added.

To work around the problem I used time instead of bars. Using a datetime variable set to the current bar time, rather than an int variable set to the current number of bars, with either CopyTime or CopyRates to get the current bar time. (Not TimeCurrent() or TimeLocal(), obviously).

* EDIT: I should probably mention that while bars seem to update in backtest, I do still get very different results when I use the time method in backtest, so perhaps the bars are not actually updating all the time in backtest when using the bars method.

 
hatlle:

What an odd coincidence. I had that exact same problem this morning!

Works fine in backtest, but not in live trading. The number of bars in the chart appears to be constant during live trading - even as new bars are added. Presumably MT5 deletes the old bars as new ones occur - but only during live trading and not in backtest?

This is clearly different to MT4, because this method of counting bars is the same one I use for detecting new bars in MT4 - and it seems to work fine there because the number of bars increases in live trade charts as new bars are added.

To work around the problem I used time instead of bars. Using a datetime variable set to the current bar time, rather than an int variable set to the current number of bars, with either CopyTime or CopyRates to get the current bar time. (Not TimeCurrent() or TimeLocal(), obviously).

* EDIT: I should probably mention that while bars seem to update in backtest, I do still get very different results when I use the time method in backtest, so perhaps the bars are not actually updating all the time in backtest when using the bars method.

Hattle,


Thanks so much.

I did another work around.

The problem raises with

int  Bars(
   string           symbol_name,     // symbol name
   ENUM_TIMEFRAMES  timeframe        // period
   );

but Bars with time works fine.

int  Bars(
   string           symbol_name,     // symbol name
   ENUM_TIMEFRAMES  timeframe,       // period
   datetime         start_time,      // start date and time
   datetime         stop_time        // end date and time

   );


So I just register robot starting time  on t1 variable in oninit by statement t1=TimeCurrent , ant then, in

ontick()

{

...

 Bars(   symbol_nametimeframe,    t1, TimeCurrent()   );

...


This is working perfect.



All the best.



Juan