running the same twice has different results??

 

Hi,

working on a mutli time frame EA that runs on a m1-chart I have to fill an array of quotes for the higher timeframes.

At the end I compare the values (tme, op, hi, lo, cl, vo) with this function:

int NumOfErr=0; double HiOfErr=0,LoOfErr=0,OpOfErr=0,ClOfErr=0,VoOfErr=0;
string checkPrc(datetime tm, double op, double hi, double lo, double cl, double vo, int mtf, int iB) {
   int err =0;
   string ret = "";
   if ( fabs(op -  iOpen(_Symbol,mtf,iB))/Point > 0.01 ){  err++; OpOfErr+= fabs(op -  iOpen(_Symbol,mtf,iB))/Point; }
   if ( fabs(hi -  iHigh(_Symbol,mtf,iB))/Point > 0.01 ){  err++; HiOfErr+= fabs(hi -  iHigh(_Symbol,mtf,iB))/Point; }
   if ( fabs(lo -   iLow(_Symbol,mtf,iB))/Point > 0.01 ){  err++; LoOfErr+= fabs(lo -   iLow(_Symbol,mtf,iB))/Point; }
   if ( fabs(cl - iClose(_Symbol,mtf,iB))/Point > 0.01 ){  err++; ClOfErr+= fabs(cl - iClose(_Symbol,mtf,iB))/Point; }
   if ( fabs(vo - iVolume(_Symbol,mtf,iB)) > 1 ){  err++; VoOfErr += fabs(vo - iVolume(_Symbol,mtf,iB)); }
   NumOfErr += err;
   if ( err > 0 || IS_DEBUG_MODE ){
      ret = StringConcatenate("sE Err  ",strTF(mtf),"  tC: ",TimeToString(TimeCurrent(),TIME_SECONDS),"  b[",iB,"]: ",TimeToString(tm)," iT) ",TimeToString(iTime(_Symbol,mtf,iB)),
            "  op: ",DoubleToString(op,Digits),"  iO: ",DoubleToString( iOpen(_Symbol,mtf,iB),Digits),": ",DoubleToString((op- iOpen(_Symbol,mtf,iB))/Point,0),
            "  hi: ",DoubleToString(hi,Digits),"  iH: ",DoubleToString( iHigh(_Symbol,mtf,iB),Digits),": ",DoubleToString((hi- iHigh(_Symbol,mtf,iB))/Point,0),
            "  lo: ",DoubleToString(lo,Digits),"  iL: ",DoubleToString(  iLow(_Symbol,mtf,iB),Digits),": ",DoubleToString((lo - iLow(_Symbol,mtf,iB))/Point,0),
            "  cl: ",DoubleToString(cl,Digits),"  iC: ",DoubleToString(iClose(_Symbol,mtf,iB),Digits),": ",DoubleToString((cl-iClose(_Symbol,mtf,iB))/Point,0),
            "  vo: ",DoubleToString(vo,0),     "  iV: ",DoubleToString(iVolume(_Symbol,mtf,iB),0),    ": ",DoubleToString((vo-iVolume(_Symbol,mtf,iB)),0),
            "  err: ",err,"  All: ",NumOfErr
            );
      //if (!IS_DEBUG_MODE) Print(ret);
      return("\n"+ret);
   }
}

I call it for the last 4 finished bars 1,..,4 this way:

   s7 = s7 + checkPrc(ArT[bar1,idx_TM,iF], ArD[bar1,idx_OP,iF], ArD[bar1,idx_HI,iF], ArD[bar1,idx_LO,iF], ArD[bar1,idx_CL,iF], ArD[bar1,idx_VO,iF], mTf, 1);
   s7 = s7 + checkPrc(ArT[bar2,idx_TM,iF], ArD[bar2,idx_OP,iF], ArD[bar2,idx_HI,iF], ArD[bar2,idx_LO,iF], ArD[bar2,idx_CL,iF], ArD[bar2,idx_VO,iF], mTf, 2);
   s7 = s7 + checkPrc(ArT[bar3,idx_TM,iF], ArD[bar3,idx_OP,iF], ArD[bar3,idx_HI,iF], ArD[bar3,idx_LO,iF], ArD[bar3,idx_CL,iF], ArD[bar3,idx_VO,iF], mTf, 3);
   s7 = s7 + checkPrc(ArT[bar4,idx_TM,iF], ArD[bar4,idx_OP,iF], ArD[bar4,idx_HI,iF], ArD[bar4,idx_LO,iF], ArD[bar4,idx_CL,iF], ArD[bar4,idx_VO,iF], mTf, 4);
   Comment(s7);
   DebugBreak();


Now I start the debugger, set the timeframe to 15 minutes and look at the chart:


It seems that everything is wrong.

Ok, I stop the debugger and re-start the debugger with the same setup immediately and now everything is correct:


Anybody with an idea?

If you look at the values the values of the array are correct but why are all(!) the function calls of iTime(), iOpen(), .. wrong the first time but correct the second time?

As I said it is the same code only called a second (and a third) time?

If I now can repeat it again with every new TF (30-min):


and the second run:


Ok, I stop here - it's getting boring.

It seems that applying the EA to a chart (no debugging) this does not happen, but I am still a bit worried.

Any idea?

 
Handle 4066 ERR_HISTORY_WILL_UPDATED, before your first fabs
void  DownloadHistory(ENUM_TIMEFRAMES aPeriod){
   ResetLastError(); (void) iOpen(_Symbol,aPeriod,0);
   if(_LastError != 0){
      if(_LastError != ERR_HISTORY_WILL_UPDATED){ Print(_LastError); return;
      Sleep(15000); RefreshRates();
   }
}

 

oh - Thanks a lot!!

But at least in the Debugger it doesn't work.

I used:

            ResetLastError(); 
            iOpen(sym,PERIOD_M1,nBar+2); 
            int gle = GetLastError();
            while (gle != 0){
               if(gle != ERR_HISTORY_WILL_UPDATED) Print(gle); 
               Sleep(500); 
               ResetLastError();
               iOpen(sym,PERIOD_M1,nBar+2); gle = GetLastError();
            }
            RefreshRates();

and still have the same problem if run in the debugger:


and the second run:


 
  1. Fifteen seconds minimum, so the it has time to download history from the network. Not 1/2 second.
  2. You can NOT check GLE the second time, it will NOT return 4066 the second time.  Get rid of the while.
  3. You code says M1 but your print out shows M15
 
WHRoeder:
Fifteen seconds minimum, so the it has time to download history from the network. Not 1/2 second.

??

The whlie-loop loops until the history is loaded - no?

(Of course I have to add a counter not to be trapped in an endless loop by another error)

 
WHRoeder:
  1. Fifteen seconds minimum, so the it has time to download history from the network. Not 1/2 second.
  2. You can NOT check GLE the second time, it will NOT return 4066.  Get rid of the while.
  3. You code says M1 but your print out shows M15

2) why not? But ok I'll check 15 sec (after some time)

3) You're right the m15 aren't updated..

 
gooly: 2) why not? But ok I'll check 15 sec (after some time)
  1. Because it doesn't.
  2. Search 4066. Do your own research.
 
WHRoeder:
gooly: 2) why not? But ok I'll check 15 sec (after some time)
  1. Because it doesn't.
  2. Search 4066. Do your own research.

Ok, I've found this! You're right.

Not really what I expect how a system behaves, but one can take care of it.