Download MetaTrader 5
To add comments, please log in or register
Publish your article. Millions of traders are looking for good ideas!
zghmql
20
zghmql 2016.03.23 16:17 

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 

Carl Schreiber
5957
Carl Schreiber 2016.03.23 20:17  

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

zghmql
20
zghmql 2016.03.23 20:35  
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  

Carl Schreiber
5957
Carl Schreiber 2016.03.23 22:20  

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!

Keith Watford
Moderator
7979
Keith Watford 2016.03.24 00:26  

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
20
zghmql 2016.03.24 01:45  
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? 


zghmql
20
zghmql 2016.03.24 01:46  
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? 
 
zghmql
20
zghmql 2016.03.24 01:47  
Do I need to refresh data before my calculations? 
Keith Watford
Moderator
7979
Keith Watford 2016.03.24 02:35  
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.

zghmql
20
zghmql 2016.03.24 07:30  
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.
zghmql
20
zghmql 2016.03.30 06:52  
I tried to use RefreshRates but it didn't work. 

Any help would be appropriate. 

Thanks 
/
To add comments, please log in or register