new bar formed?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
1815
SDC 2014.09.06 20:17 #
 
maindoor:

  Is time really that reliable ?

  The granularity of Time[0] is in seconds, so if

  within the first second you get two ticks, it would

  count as two newbars. :/



  The Time[] array holds the open time of each bar. By the time the second tick comes the time var is already updated to the new Time[0]

 

static datetime time = Time[0];

if(Time[0] > time)
{
 time = Time[0]; //newbar, update time
} 
avatar
13006
WHRoeder 2014.09.06 21:24 #
 
maindoor:   The granularity of Time[0] is in seconds, so if within the first second you get two ticks, it would count as two newbars. :/
   static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
How would that happen. The code doesn't say to look at TimeCurrrent(), it says to look at Time[0]. The first tick received, (you can miss ticks,) the static doesn't match, new bar detected. Then for the rest of the bar (1 minute, 1 month) they do, same bar.

avatar
13006
WHRoeder 2014.09.06 21:27 #
 
SDC: The Time[] array holds the open time of each bar. By the time the second tick comes the time var is already updated to the new Time[0]
if(Time[0] > time)
Use not equal, not greater. There's a post a few years ago where the server clock was off on days, not time. When it reset, EA stopped working for days

avatar
39
maindoor 2014.09.07 23:13 #
 
SDC:

  The Time[] array holds the open time of each bar. By the time the second tick comes the time var is already updated to the new Time[0]

 


yes, you're right. My bad.
avatar
28
danik 2015.09.23 12:02 #
 

again with new bar detection. i received the following message in Experts log (after MT4 upgraded)

"2015.09.23 12:45:58.276 sazon_4waves_03 XAUUSD,M5: array out of range in 'sazon_4waves_03.mq4' (89,12)"

here is the code of that area 

https://gyazo.com/0ba6dd69466d430a1cd99339d56b9f8a(picture just to show line 89)

bool NewBar()
{
   if (Time[0] != newBar){// line 89
      newBar = Time[0];
      return true;
   }
   return false;
}

 

so the error when accessing Time[0]... is it my problem only, some more reliable methods of detecting new bars were found, or this is problem of a new terminal?

 

edited, thank you, GumRai. 

avatar
Moderator
3419
GumRai 2015.09.23 12:08 #
 

Why don't you just paste the relevant code using the SRC button?

Then we don't have to go look at another webpage to see what you are talking about. 

avatar
13006
WHRoeder 2015.09.23 13:56 #
 
avatar
28
danik 2015.09.23 14:17 #
 
no, i call it from OnTick(). thank you, WHRoeder.
avatar
Moderator
3419
GumRai 2015.09.24 00:53 #
 

danik,

If you are only calling this function from OnTick, then it is a concern. 

I would think that you could only get this error if there is absolutely no history loaded for the chart symbol.

How often do you get this error? Is it just at opening the terminal?

bool NewBar()
{
   if(ArraySize(Time)==0)
      return(false);
   if (Time[0] != newBar){// line 89
      newBar = Time[0];
      return true;
   }
   return false;
}

 may be a work around, but it shouldn't really be necessary

Back to topics list   | 1 2  

To add comments, please log in or register