I am trying to generate a 2D array of high, low, open, close prices and I am totally lost as to how to fill the array.
This doesn't look a great way to fill the array. Also for some reason the last print value is zero (i.e the iClose value for the first candle is zero - the first 3 values are correct.).
Is there a better way to do this?
thanks
I sorted the zero value problem.
Would still be grateful for comments on whether I have used best approach to create the 2D array.
thanks
int tfPeriods[]={ 0, PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1 }; string tfAsText[]={ "n/a", "M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1" }; #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 int MyArrayCopyRates(double& acr[][ACR_COUNT], string s="", int p=0){ if(s == "") s=Symbol(); if(p == 0) p=Period(); for(int iTf = 1; p > tfPeriods[iTf]; iTf++){} for(int res= -1; res <= 0;){ //{https://www.mql5.com/en/forum/129734/page2 says ArrayCopyRates is a nonreent- // rant, non-thread-safe call. Therefor you must put a mutex around the //}call in case of multiple EAs on multiple charts. GetTradeContext(); res = ArrayCopyRates(acr, s, p); int gle = GetLastError(); RelTradeContext(); if(res > 0) break; if (gle != ERR_HISTORY_WILL_UPDATED){ DisableTrading("No "+s+"/"+tfAsText[iTf]+" history: " + gle); return(res); } Comment("Updating history for "+s+"/"+tfAsText[iTf]+" chart"); LogMe("Updating history for "+s+"/"+tfAsText[iTf]+" chart"); Sleep(15000); SetNeedToRefresh(); } // for if(acr[0][ACR_TIME] != 0.) return(res); // Verify data DisableTrading( "No "+s+"/"+tfAsText[iTf]+" history: " + GetLastError() ); return(0); } : double m1_acr[][ACR_COUNT]; void OninitMasar(){ MyArrayCopyRates(m1_acr, market_pair, PERIOD_M1); } : lastLE [iMasar] = m1_acr[iLEc][ACR_TIME];
Not sure I understand your first question - why fill it more than once?
What do these functions do in your code?: GetTradeContext(); & RelTradeContext();
- after 4 hours your array is outdated when a new H4 bar forms. You're not expecting your array to update itself like ACR does.
- Mutex like the comment says. From my code
Yes, my code above was very basic because i was struggling to find decent examples of how to fill a 2D array in a loop. i understand about updating with new candles.
I am not a programmer and have no idea what a 'mutex' is!
thanks for your help anyway.
err.yeh still didn't help
It just means coding to prevent one process changing data values another related process requires not to be changed in order to succeed.. or something like that, lol
err.yeh still didn't help
From the wiki article . . .
In computer science, mutual exclusion refers to the requirement of ensuring that no two processes or threads (henceforth referred to only as processes) are in their critical section at the same time. Here, a critical section refers to a period of time when the process accesses a shared resource, such as shared memory.
From the wiki article . . .
thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to generate a 2D array of high, low, open, close prices and I am totally lost as to how to fill the array.
This doesn't look a great way to fill the array. Also for some reason the last print value is zero (i.e the iClose value for the first candle is zero - the first 3 values are correct.).
Is there a better way to do this?
thanks