Download MetaTrader 5

Unexpected behavior of CopyClose in Version 5.00 Build 655 on Win 7 64bit

To add comments, please log in or register
MQL5.community allows users to store their source codes in MQL5 Storage. Try it!
Adam W
40
Adam W 2012.07.08 20:25 

I have reduced a bug in an indicator I am working on to a reproducible case of unexpected behavior with CopyClose. 

#property indicator_separate_window

#property indicator_buffers 0
#property indicator_plots 0
int OnInit()
  {
   IndicatorSetString(INDICATOR_SHORTNAME,"copyclose_bug_demo");
   return(0);
  }
int OnCalculate(const int     rates_total, // size of incoming time series
                const int prev_calculated, // processing of bars on the previous request
                const datetime&    time[], // Time
                const double&      open[], // Open
                const double&      high[], // High
                const double&       low[], // Low
                const double&     close[], // Close
                const long& tick_volume[], // Tick Volume
                const long&      volume[], // Real Volume
                const int       &spread[])
  {
   int start;
   if(prev_calculated==0)
     {
      start=1;
        } else {
      start=prev_calculated-1;
     }

   for(int i=start; i<rates_total && !IsStopped(); i++)
     {
      double closes1[1];
      double closes2[1];
      if(CopyClose("AUDNZD",PERIOD_M1,time[i],1,closes1))
        {
         if(CopyClose("AUDNZD",PERIOD_M1,time[i],1,closes2))
           {
            if(closes1[0]!=closes2[0])
              {
               Print("Non-determinism in CopyClose.");
              }
           }
        }
     }

   return(rates_total);
  }

Steps to reproduce: 

1. Set debugger options to use specified symbol and period: EURUSD, M1.

2. Set max bars per chart at 500k.

3. Pre-load chart data for EURUSD and AUDNZD.

4. Set breakpoint at the print statement.

5. Start debugger.

 

Observed: 

On some runs, indicator stops at the breakpoint, in various states. This is non-deterministic.

Example error state 1:

closes1[0] = 1.36223
closes2[0] = 1.36213
time[i] = D'2011.03.09 02:53:00'

Example error state 2:

closes1[0] = 1.31115
closes2[0] = 1.3112
time[i] = D'2011.06.17 09:23:00'

Example error state 3:

closes1[0] = 0
closes2[0] = 1.36595
time[i] = D'2011.03.03 16:35:00' 

 etc.

 

Sometimes it runs without error repeatedly. In that case, I can do something in the MetaTrader Terminal, such as open and close a few charts. Then, the unexpected behavior will re-appear.

 

By the way, this has been an extremely elusive bug to isolate without proper debugging tools.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Client Terminal Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Client Terminal Properties - Documentation on MQL5
onewithzachy
2271
onewithzachy 2012.07.09 04:36  

Hi adamuu,

I'm using Vista HB 32 install MT5 on C:\Program Files\... but I change the security description. 

Could you please attach the mq5 and the compiled .ex5 ? We may have different compiled result.

I had print problem here https://www.mql5.com/en/forum/6985#comment_215269 

:D 

convertir indicator MT4 versMT5
  • www.mql5.com
convertir indicator MT4 versMT5.
Adam W
40
Adam W 2012.07.10 17:38  
onewithzachy:

Hi adamuu,

I'm using Vista HB 32 install MT5 on C:\Program Files\... but I change the security description. 

Could you please attach the mq5 and the compiled .ex5 ? We may have different compiled result.

I had print problem here https://www.mql5.com/en/forum/6985#comment_215269 

:D 

Okay, if it helps.

How can I get the MetaTrader 5 developers to notice this thread? Is this the correct channel for reporting bugs?

onewithzachy
2271
onewithzachy 2012.07.10 17:41  
adamuu:

Okay, if it helps.

How can I get the MetaTrader 5 developers to notice this thread? Is this the correct channel for reporting bugs?

Hi adamuu,

No, use service desk, you can find it on your profile page.

:D 

Alexey Da
Moderator
6598
Alexey Da 2012.07.11 10:11  
Why don't you check CopyClose result and last error?
Documentation on MQL5: Checkup / GetLastError
  • www.mql5.com
Checkup / GetLastError - Documentation on MQL5
Adam W
40
Adam W 2012.07.11 16:32  
alexvd:
Why don't you check CopyClose result and last error?

I am checking copyclose result in both instances. If it's zero in either instance, i'm not going to compare the output, closes1[0] and closes2[0]. (see the if's)

There is no point in GetLastError() if CopyClose returned nonzero. Right?

Adam W
40
Adam W 2012.07.12 07:01  

I see, CopyClose returns -1 in case of error.  Let me see if I can still reproduce this problem.

 

Alexey Da
Moderator
6598
Alexey Da 2012.07.12 07:50  

Yes. All CopyXXX functions return -1 on error and set last error to non zero value. In this case there is no sence trying to use values in output array. They might be wrong.

Documentation on MQL5: Checkup / GetLastError
  • www.mql5.com
Checkup / GetLastError - Documentation on MQL5
Adam W
40
Adam W 2012.07.12 08:05  
This appears to be my mistake. Thanks for the help.
To add comments, please log in or register