Download MetaTrader 5

Does "Volume[0]>1" means this is not a new bar?

To add comments, please log in or register
thomas2004
175
thomas2004  

Hi,


I see from an EA followings:

...
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
...

It seems only when the Volume[0] = 1. it is a new bar, right?

Carl Schreiber
Moderator
7944
Carl Schreiber  
thomas2004:

Hi,


I see from an EA followings:

It seems only when the Volume[0] = 1. it is a new bar, right?

That's a very old way to do it.

You'd better check the time:

   static datetime tmeBar0;
   bool newBar = false;
   ...
   if ( tmeBar0 != Time[0] ) {
      tmeBar0 = Time[0];
      newBar = true;
   }
(not tested)
whroeder1
17063
whroeder1  
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 forum.) Always use time. New candle - MQL4 forum
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
To add comments, please log in or register