datetime events[];
ArrayResize(events, totalEvents);
Thanks! Out of curiosity, how expensive is that ArrayResize() function?
vgoklani:
Thanks! Out of curiosity, how expensive is that ArrayResize() function?
Haven't extensively tested it. I think it depends on the size. Once I stumbled upon an EA that (amongst other things) added values to an array after every bar, increasing the array by 1 every time. After a few thousand bars in the strategy tester it became painfully slow and after modifying the EA to increase the array in larger steps of 10% of its size at once it became notably faster again.
Thanks! Out of curiosity, how expensive is that ArrayResize() function?
If you're wanting to keep resizing an array, I would suggest that you re-evaluate your logic, especially of array keeps getting larger.
Array techniques I use are:
- if say varying from 5 to 10, then fix size at 10 but use another variable for size. e.g. double MyArray[10] & int MyArraySize = 7;
- if 'all historical values' then use say double MyHistory[100] and treat it as circular buffer, actually just holding 'last 100 values'
(for circular buffer, either use 'circular index' or else 'shuffle entries & drop oldest' as you add next value )

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
Hi,
How do you create a dynamically sized array in mql4? Is there a *new* construct? I can't even use a variable to define the array size:
int totalEvents = 7;
datetime events[totalEvents];
:(