Bug with CopyRates()

 

Hello,

There seems to be a bug with copy functions when we have two consecutive calls to  eg CopyRate(), where we get different results compared to single calls..

Since the problem appears on consecutive call, in the example below, first a) run the first block (currday), b) comment out that and run the second block (prevday), c) finally uncomment all blocks 

(I used eg MetaQuotes demo server, on symbol Indexes/US500M)

  

        MqlRates rates[]; 
        double rsum=0;  
                
        datetime currday=1781616600, 
                 prevday=currday-86400; 
                 
        //      //  
                  
        Alert("***"); //  make some room
         
        //  ** curday **
                  
        CopyRates(Symbol(), PERIOD_M2,
                  currday, currday+3600, rates); 
           
        for (long bcount=0, bsize=ArraySize(rates); bcount<bsize; ++bcount)
                  
                rsum+=rates[bcount].close;
                                 
        Alert("rsum currday for ", currday, " should be ",
                 DoubleToString(rsum/ArraySize(rates), 2));    
      
        //  ** prevday **  
         
/*      CopyRates(Symbol(), PERIOD_M2,  
                  prevday, prevday+3600, rates );
           
        for (long bcount=0, bsize=ArraySize(rates); bcount<bsize; ++bcount)
          
                rsum+=rates[bcount].close;
                         
                Alert("rsum for prevday ", prevday, " should be ",  
                         DoubleToString(rsum/ArraySize(rates), 2)); */  

greets

 
democog:

Hello,

There seems to be a bug with copy functions when we have two consecutive calls to  eg CopyRate(), where we get different results compared to single calls..

Since the problem appears on consecutive call, in the example below, first a) run the first block (currday), b) comment out that and run the second block (prevday), c) finally uncomment all blocks 

(I used eg MetaQuotes demo server, on symbol Indexes/US500M)

 

 

greets

What bug ? You didn't even say or show what the problem is. 
 
Alain Verleyen #:
What bug ? You didn't even say what the problem is. 

I posted the code instead of doing the explanation, but here it is anyway:

a) If we call CopyRates() alone (and do some processing on the rates), for eg "today", we come up with some value "aval"

b) If we call CopyRates(), again alone but for eg "yesterday", we get some other value "bval"

c) But if we run both, one after another, then the new "bval" is different from the previous bval (of step "b"), although params have not changed 

greets

PS It seems the code example was missing (maybe because I was doing some changes at the time :))
 
        //  ** prevday **  
        rsum=0;   
 
oh well "case" closed hehe 
 
democogThere seems to be a bug with copy functions
        CopyRates(Symbol(), PERIOD_M2,

On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
          Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018)
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019)