Help needed

 

Hi all,

 I try to synchronize the bars of different pairs into a three dimensional array so each shift (bar) of this array has the same time stamp.

If the bar for a certain time and pair doesn't exist, it still should get a time stamp but the other values should be -1.

I have come up with the below function but if the last loop is ran to check if all the time stamps for the different second dimensions "b" are the same, they are not.

Could someone please point me in the direction where I go wrong? At this moment, I fail to spot the problem.  Thanks!


extern int Time.Frame   =60;
extern int  Pairs       =6; 
extern int Week.Start.Day =0;
extern int Week.Start.Hour=17;

double  SERIES[0,6,6];
string  PAIRS[6]={"EURUSD","EURCHF","GBPUSD","USDCHF","USDJPY","EURJPY"};

void Set.series(){
 
 int sec=Time.Frame*60;
 int time.start=iTime(Symbol(),Time.Frame,1);
 int wkd = 60*60*48;
 int cnt.wkd;
 int time.cur;
 int shift;
 double bad, good;
 
 ArraySetAsSeries(SERIES,true);
 ArrayResize(SERIES,range);
 
 
 for(a=0;a<range;a++){
     for(b=0;b<Pairs;b++){

         time.cur=time.start-(sec*a)-((wkd+sec)*cnt.wkd);   
         
         shift=iBarShift(PAIRS[b],Time.Frame,time.cur,true);
        
         if(shift<0){
            SERIES[a,b,0]=time.cur;
            SERIES[a,b,1]=shift;
            SERIES[a,b,2]=shift;  
            SERIES[a,b,3]=shift;
            SERIES[a,b,4]=shift;
            SERIES[a,b,5]=shift;
            bad++;
            }
         else{SERIES[a,b,0]=iTime(PAIRS[b],Time.Frame,shift);
              SERIES[a,b,1]=iOpen(PAIRS[b],Time.Frame,shift);
              SERIES[a,b,2]=iClose(PAIRS[b],Time.Frame,shift);  
              SERIES[a,b,3]=iHigh(PAIRS[b],Time.Frame,shift);
              SERIES[a,b,4]=iLow(PAIRS[b],Time.Frame,shift);
              SERIES[a,b,5]=iVolume(PAIRS[b],Time.Frame,shift);
              good++;
            
              if(iTime(PAIRS[b],Time.Frame,shift)!=time.cur)Print(shift);
             }

         if(TimeDayOfWeek(time.cur) == Week.Start.Day &&
            TimeHour(time.cur)      <= Week.Start.Hour&&
            TimeMinute(time.cur)    == 0                 )cnt.wkd++;
              
    
        }
      
      }

 Print(good/(bad+good));
 Print("Good=",good,"--Bad=",bad,"-WKD=",cnt.wkd);
 

for(a=0;a<range;a++){

   if(TimeHour(SERIES[a,0,0])!=TimeHour(SERIES[a,1,0]))Print(TimeHour(SERIES[a,0,0]),"-1-",TimeHour(SERIES[a,1,0]));
   if(TimeHour(SERIES[a,1,0])!=TimeHour(SERIES[a,2,0]))Print(TimeHour(SERIES[a,1,0]),"-2-",TimeHour(SERIES[a,2,0]));
   if(TimeHour(SERIES[a,2,0])!=TimeHour(SERIES[a,3,0]))Print(TimeHour(SERIES[a,2,0]),"-3-",TimeHour(SERIES[a,3,0]));
   if(TimeHour(SERIES[a,3,0])!=TimeHour(SERIES[a,4,0]))Print(TimeHour(SERIES[a,3,0]),"-4-",TimeHour(SERIES[a,4,0]));
   if(TimeHour(SERIES[a,4,0])!=TimeHour(SERIES[a,5,0]))Print(TimeHour(SERIES[a,4,0]),"-5-",TimeHour(SERIES[a,5,0]));
   }
 
}
 
Dingetje:

Hi all,

 I try to synchronize the bars of different pairs into a three dimensional array so each shift (bar) of this array has the same time stamp.

If the bar for a certain time and pair doesn't exist, it still should get a time stamp but the other values should be -1.

I have come up with the below function but if the last loop is ran to check if all the time stamps for the different second dimensions "b" are the same, they are not.

Could someone please point me in the direction where I go wrong? At this moment, I fail to spot the problem.  Thanks!

What is range ?  what is it declared as ? what is it's value ?
 
What effect does ArraySetAsSeries() have on a multi dimensional array ?
 
RaptorUK:
What is range ?  what is it declared as ? what is it's value ?

Hi Raptor,
With the below function I get the range. And btw, it is a script.
extern int Bars.        =50;
extern bool All.Bars    =true;

int range;  //declared at global level


range=GetRange(); //in start

int GetRange(){
int i;
int tr=99999999;

  for(i=0;i<Pairs;i++){
      if(iBars(PAIRS[i],Time.Frame)<tr)tr=iBars(PAIRS[i],Time.Frame); 
      }
  
  if(All.Bars)return(tr);
  if(!All.Bars)return(MathMin(Bars.,tr)); 
}
 
RaptorUK:
What effect does ArraySetAsSeries() have on a multi dimensional array ?
Now you point it out, I think it does nothing. I suppose I thought it would set the first dimension as series but the documentation doesn't mention anything about it.
I removed the line  but the issue remains.
 

Try setting   time.cur = time.start;  otherwise your range of bars may be beyond the last bar for some of your pairs. 

 
RaptorUK:

Try setting   time.cur = time.start;  otherwise your range of bars may be beyond the last bar for some of your pairs. 


I'm not sure what you mean here.

time.cur is in any case equal to or smaller than time.start. Each iteration "a" an amount in seconds equal to the duration of the bar plus any weekend is substracted:  time.cur=time.start-(sec*a)-((wkd+sec)*cnt.wkd);  

If a bar doesn't exist, the time slot of that bar should still exist with the time stamp in the SERIES array. So for example during christmass, the time slots are in the array with the correct time stamps but with ochl and volume value -1.
 
Dingetje:

I'm not sure what you mean here.
Sorry,  I'm reading your code wrong.
 
Dingetje:
I try to synchronize the bars of different pairs into a three dimensional array so each shift (bar) of this array has the same time stamp.
Why bother. Just use ArrayCopyRates and you have all values. No copying needed.
  #define ACR_TIME     0  // Array Copy Rates
  #define ACR_OPEN     1
  #define ACR_LOW      2
  #define ACR_HIGH     3
  #define ACR_CLOSE    4
  #define ACR_VOLUME   5
     #define ACR_COUNT    6
double _EURUSD[][ACR_COUNT], _EURJPY[][ACR_COUNT] ...
int init(){
   //{https://www.mql5.com/en/forum/129734/page2 says ArrayCopyRates is a nonreentrant,
   // non-thread-safe call. Therefor you must put a mutex around the call in
   // case of multiple EAs on multiple charts. Alteratively, since init() is
   // single threaded across all charts, put all ACRs there.
   //)
   ArrayCopyRates(_EURUSD, "EURUSD", Time.Frame); #define EURUSD 0 
   ArrayCopyRates(_EURJPY, "EURJPY", Time.Frame); #define EURJPY 1
   :
}
double GetSeries(int ePair, int eACR, int iBar){ switch(ePair){
   case EURUSD: return( _EURUSD[iBar][eACR] );
   case EURJPY: return( _EURJPY[iBar][eACR] );
   :
int start(){
   Print("EURUSD close[0]=",PriceToStr(GetSeries(EURUSD,ACR_CLOSE,0)));
 
WHRoeder:
Why bother. Just use ArrayCopyRates and you have all values. No copying needed.
Hi WHRoeder,

Thanks for the suggestion but from what I gather ArrayCopyRates doesn't account for missing bars in the history base. I tested it and from what I see it copies the available bars
from the history base to the array so if there are any missing bars in any of the pairs, the index/time stamp go out of sync for the different pairs. If I am missing something from your post that avoids this problem, please tell.

 

Hi,

I found the problem.  I was looking for the problem in the wrong places.

This weekend addition was in the second for loop but it belonged in the first loop. In the second loop it kept adding weekends per currency pair.

if(TimeDayOfWeek(time.cur) == Week.Start.Day &&
            TimeHour(time.cur)      <= Week.Start.Hour&&
            TimeMinute(time.cur)    == 0                 )cnt.wkd++;


Also I corrected time.cur=time.start-(sec*a)-((wkd+sec)*cnt.wkd);

It should be:  time.cur=time.start-(sec*a)-(wkd*cnt.wkd); As the extra bar was already substracted because of the nex iteration.