Best way to handle array/list of object MQL5. Critical error while running expert. Array out of range.
Your critical error is because you didn't dimension _neurons[]. That would be true whether it was an array of objects or any other type. Adding the line:
ArrayResize(_neurons, ArraySize(_neurons) + 1);
before the offending line, inside the loop, would fix it.
As for your title question, I have used this with good results.
https://www.mql5.com/en/docs/standardlibrary/datastructures/carrayobj
Your critical error is because you didn't dimension _neurons[]. That would be true whether it was an array of objects or any other type. Adding the line:
before the offending line, inside the loop, would fix it.
As for your title question, I have used this with good results.
https://www.mql5.com/en/docs/standardlibrary/datastructures/carrayobj
Don't do it this way, if there are a lot of neurons, it will be slow.
As the size is known before the loop you can just do :
ArrayResize(_neurons, ArraySize(thresholds));
Or alternatively, inside the loop :
ArrayResize(_neurons, ArraySize(_neurons) + 1, ArraySize(thresholds));I would also suggest to use a size variable instead of calling ArraySize() on each iteration of the loop.
Your critical error is because you didn't dimension _neurons[]. That would be true whether it was an array of objects or any other type. Adding the line:
before the offending line, inside the loop, would fix it.
As for your title question, I have used this with good results.
https://www.mql5.com/en/docs/standardlibrary/datastructures/carrayobj
Don't do it this way, if there are a lot of neurons, it will be slow.
As the size is known before the loop you can just do :
Or alternatively, inside the loop :
I would also suggest to use a size variable instead of calling ArraySize() on each iteration of the loop.Don't do it this way, if there are a lot of neurons, it will be slow.
Indeed. I should have spelled this out more fully like I did in this post:
Indeed. I should have spelled this out more fully like I did in this post:
I knew you knew but now I had the others let know.
By the way you can also use the Pocket tools, it's nicer and quicker.
Thanks! Is this a better approach than using a CList?
It is better than CList but not better than CArrayObj. The latter wraps a C-style array and for all intensive purposes is equally as performant. Your code will also be much more elegant and readable, and it will also save you a lot of developer time.
- 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've designed a library system I'm trying to implement in MT5, I'm having difficulty managing lists of objects. What would be the best approach to making a list of objects?
I've tried things like this:
This for some reason is also not allowed.