Pooya Khamooshi: wham am I doing wrong?
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - You copy an object in _runningOrders[] and name it current. You create a pointer of current named result. You return result. On return all objects in the function are released including current, so the pointer becomes bogus.
- Simplify, return an index to _runningOrders[] or EMPTY.
William Roeder:
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - You copy an object in _runningOrders[] and name it current. You create a pointer of current named result. You return result. On return all objects in the function are released including current, so the pointer becomes bogus.
- Simplify, return an index to _runningOrders[] or EMPTY.
Thanks William, I've edited.
does this line really make a copy of the object?! I just wanted a variable pointing to the same object.
RunningOrder current = _runningOrders[i];
Maybe I should use the pointer but I tried and it gives me the "invalid pointer access":
RunningOrder *current = _runningOrders[i];
Good idea, I will return the index but just that I needed to return the actual object that is found from this method, not copying it or anything. How'd you return the object which was found then?
Ok, this is the solution and it works fine :), just getting a pointer to the object in the array and returning it like C#.
RunningOrder* RunningOrdersHelper::LowestBuyOrder() { RunningOrder *result = NULL; for(int i = 0; i < ArraySize(_runningOrders); i++) { RunningOrder *current = GetPointer(_runningOrders[i]); if (current.Type != OP_BUY) continue; if (result == NULL) result = current; else if (current.OpenPrice < result.OpenPrice) result = current; } return result; }

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
I have the below method, but it returns an invalid pointer, wham am I doing wrong?