LukeB:
Just a question on if there is a way to assign an array to a reference variable (Pointer) in MQL 4 language. I seem to always be working around this by sizing and copying array elements.
Example segments for an EA that does different things at different times on different days, so I have these time arrays detailing at what times an activity may be valid:
Just wondering if anyone has a good solution in MQL4 / am I missing something to make this work easily in the language.
Not sure I'm 100% following what you are trying to do . . . but couldn't you just use a 2D array where the first dimension was the day number ?
Just a question on if there is a way to assign an array to a reference variable (Pointer) in MQL 4 language. I seem to always be working around this by sizing and copying array elements.
Example segments for an EA that does different things at different times on different days, so I have these time arrays detailing at what times an activity may be valid:
Just wondering if anyone has a good solution in MQL4 / am I missing something to make this work easily in the language.
RaptorUK:
Not sure I'm 100% following what you are trying to do . . . but couldn't you just use a 2D array where the first dimension was the day number ?
Not sure I'm 100% following what you are trying to do . . . but couldn't you just use a 2D array where the first dimension was the day number ?
2D array is a potential solution for this specific example. But, you run into problems with the data types needing to be different in the different dimensions (int versus date-time), and the use of ArraySize() to step through elements in the array is less clear. You can send a reference to a function, I just haven't found a way to send one back to the caller. But, there is always a way.
LukeB: 2D array is a good solution - I just haven't found a way to send one back to the caller.
double ar[][2]; int nAr = Function(ar); : int Function(double& ar[][2]){ // Pass by reference ArrayResize(ar, 3) ar[2][1] = 0; return(3);
LukeB:
2D array is a potential solution for this specific example. But, you run into problems with the data types needing to be different in the different dimensions (int versus date-time), and the use of ArraySize() to step through elements in the array is less clear. You can send a reference to a function, I just haven't found a way to send one back to the caller. But, there is always a way.
Why do you need to ? just copy the correct array to a "CorrectDayArray" and work from that, would that solve your issue ?
2D array is a potential solution for this specific example. But, you run into problems with the data types needing to be different in the different dimensions (int versus date-time), and the use of ArraySize() to step through elements in the array is less clear. You can send a reference to a function, I just haven't found a way to send one back to the caller. But, there is always a way.
RaptorUK:
Why do you need to ? just copy the correct array to a "CorrectDayArray" and work from that, would that solve your issue ?
Why do you need to ? just copy the correct array to a "CorrectDayArray" and work from that, would that solve your issue ?
That works - as mentioned in the opening post: "I seem to always be working around this by sizing and copying array elements.".
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Example segments for an EA that does different things at different times on different days, so I have these time arrays detailing at what times an activity may be valid:
Just wondering if anyone has a good solution in MQL4 / am I missing something to make this work easily in the language.