Array out of range while looping through positions due to one or more position closed or opened during the loop
get rid of this condition
if(totpos>0) { }
And is there a way to get notified if the EA crashes due to an error handling (ie array out of range)?
void OnDeinit(const int reason){ SendNotification("EA closed down. the reason code : ", reason); }
get rid of this condition
And is there a way to get notified if the EA crashes due to an error handling (ie array out of range)?
Thank you.
I will try this.
Hello, my first question so i may not get this right but i do have a problem i cannot seem to solve.
As a part of an EA i gather the information about the positions - and if a position is close or opened while in that information gathering loop i get an "Array out of range"; obviously.
Is there a way to circumvent this?
And is there a way to get notified if the EA crashes due to an error handling (ie array out of range)?
Thank you
Thank you - would someone mind explaining the reasoning behind as to why there would be a difference?
Hello, my first question so i may not get this right but i do have a problem i cannot seem to solve.
The position can be closed manually or by another EA.
Therefore, you should first create your own array with tickets, and then iterate over your array, checking whether the position is open or closed.
That is, you need to work with your own array and not with the MetaTrader array.
Thank you yes i do understand why the problem occurs - and it actually does so for me repeatedly.
If you've got the time would you mind expanding on the error handling?
The position can be closed manually or by another EA.
Therefore, you should first create your own array with tickets, and then iterate over your array, checking whether the position is open or closed.
That is, you need to work with your own array and not with the MetaTrader array.
Thank you. Have you got an idea as to how i would do that? My worry is that even during the creation of my own array the same problem may occur, that the EA has closed one or more positions during the loop.
creating your own array will not stop a position being closed during your processing so will make no difference to the problem.
cycle through the positions in the reverse loop as I stated this should eliminate array out of range errors.
My worry is that even during the creation of my own array the same problem may occur, that the EA has closed one or more positions during the loop.
Tickets in your array are not changed by anyone except you, they will not disappear anywhere.
If the position for some ticket is already closed, you will not be able to select it using "PositionSelectByTicket".
And you will have tickets of your positions, which you do not need to look for somewhere in the history of deals.
If "PositionSelectByTicket" returns false - then the position is already closed and you can check how it was closed, with what profit, when, etc. (you already have a ticket)
You can also sort these tickets as you need, select tickets separately for closing and track your tickets specifically in "OnTradeTransaction".
Ignoring other deals.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, my first question so i may not get this right but i do have a problem i cannot seem to solve.
As a part of an EA i gather the information about the positions - and if a position is close or opened while in that information gathering loop i get an "Array out of range"; obviously.
Is there a way to circumvent this?
And is there a way to get notified if the EA crashes due to an error handling (ie array out of range)?
Thank you