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 ?
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)); }
Try setting time.cur = time.start; otherwise your range of bars may be beyond the last bar for some of your pairs.
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.
I'm not sure what you mean here.
.
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.
#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)));
Why bother. Just use ArrayCopyRates and you have all values. No copying needed.
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!