My code is acting very strange, having trouble with arrays

 

So i create a multidimensional array, 2 of them to be exact as an example.

arrbuy[][3]

arrsell[][3]


these will store all my buy and sell positions that are open. I then populate the index with arrayresize and use the number of open positions as the size of the first dimension for both arrays. I then run a for loop and populate each array starting with index 0 for all buy and sell positions. My next step is to use the arraysort function to sort it from lowest to highest as I will need them in that order. I then do an additional resize to cut off the extra positions at the end which were not populated. 

This is where I am running into issues. After doing all this I run the script and try to list the data from the array. Now at first it works out fine but after a while the script will for some odd reason get stuck on the lowest all time position value from my first index. By this I mean arrbuy or arrsell[0][0] is supposed to list my current profit. It will continually update on each tick showing what the profit is but instead of that happening what actually happens is it will always show the lowest profit that I ever had then arrsell[1][0] will show the exact same ticket but will show the current value. I'm incredibly confused by this. The loop I created runs through all my positions and lists them all in the array so I'm not sure why its storing it in this manner. Furthermore why is it saving the lowest position in the first index spot when the for loop that I pull up at the begging of the function specially says index [0][0] = current profit of first ticket, index [1][0] = current profit of second open tick, etc....

I've tried adding arrayfree() to the end of the function just to try to clear up the array for the next time it runs but nothing is working. I even tried ArrayRemove() before doing ArrayFree() even though I know that's not how ArrayRemove() is supposed to be used. I simply did it out of desperation.

Does anyone have any idea what's going on?


Example of my code

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: