Open and Close arrays

 

Hi all,

 

I wonder if someone could help me out. It's driving me crazy. 

 

I have the following code:

 

// Check previous candle and previous of previous candle
   double bar1=Close[1]-Open[1];
   double bar2=Close[2]-Open[2];
   Print("CheckEntry");

   Print("bar1 "," Close[1]: ",Close[1]," - "," Open[1]: ",Open[1]," = ",Close[1]-Open[1]);
   Print("bar2 "," Close[2]: ",Close[2]," - "," Open[2]: ",Open[2]," = ",Close[2]-Open[2]);

 

 

 This is the print screen:

 

 

 

The values Open and Close for the previous candle and previous of previous candle are wrong.

 

If I stop the EA and run it again for same, it works as expected:

 

 

 

 

 I initiate the code only once per bar:

 

static datetime Time0;
   if(Time0==Time[0])
     {
      return;
     }
   Time0=Time[0];



// Check for entry condidtions and set a stop order
   bool checkentry=CheckEntry();

 

 

Any idea why Open and Close values for [1] and [2] might be wrong? This doesn't happen always though, it happens randomly.

 

 

Thanks 

 

This can happen if start of your EA got a tick but has no history yet.

I check for Tickvalue to be greater 0 or check Bars > 100

 
gooly:

This can happen if start of your EA got a tick but has no history yet.

I check for Tickvalue to be greater 0 or check Bars > 100

What do you mean by "start of your EA got a tick but has no history yet"? The EA was running since Monday so the start of the EA is Monday, today is Wednesday when the error happened. I don't fully understand how no history yet.  Can you please explain it?

 Surely the chart has more than 100 bars. The EA worked before on same chart. The error happens randomly.

Thanks  

 

I mean if you start the terminal with charts with EAs and/or indicators. They all could get a tick while all the information from the server has not been loaded - kind of thread race.

If it happens randomly may be the quotes of the broke have 'wholes'?

Print(..) the necessary information in those cases!

 

Are you sure that you do not have a similar block of code elsewhere?

I don't believe that a print of a calculation using doubles can print as -0, it would be printed as something like -1e015, if it was exactly zero, it would print as 0.0

 
gooly:

I mean if you start the terminal with charts with EAs and/or indicators. They all could get a tick while all the information from the server has not been loaded - kind of thread race.

If it happens randomly may be the quotes of the broke have 'wholes'?

Print(..) the necessary information in those cases!

I'm already printing the open and close for [1] and [2].

What else do I need to print? 


 
GumRai:

Are you sure that you do not have a similar block of code elsewhere?

I don't believe that a print of a calculation using doubles can print as -0, it would be printed as something like -1e015, if it was exactly zero, it would print as 0.0


Yes I'm sure. It's just this code I have. 

What can cause this errors? 
 
 
Do I need to refresh data before my calculations? 
 
GumRai:

Are you sure that you do not have a similar block of code elsewhere?

I don't believe that a print of a calculation using doubles can print as -0, it would be printed as something like -1e015, if it was exactly zero, it would print as 0.0


zghmql:
Yes I'm sure. It's just this code I have. 

What can cause this errors? 
 

I can suggest nothing. The prints that you show should not be possible from that code.

Maybe you should show the whole code.

 
GumRai:

I can suggest nothing. The prints that you show should not be possible from that code.

Maybe you should show the whole code.

Well it is, hence why I posted it asking for explanation and help.
 
I tried to use RefreshRates but it didn't work. 

Any help would be appropriate. 

Thanks 
Reason: