PositionInfo from an Expert showing in another EA scope

 

Hi,


something curious just happened:


Possible bug

As you can see in the image, I'm operating futures in Brazil's B3 exchange in a hedging account running more then one EA. In a given moment, EA 90002 set its take profit value to be 111045. Later, when two different EAs, 40008 and 30008, called PositionInfoDouble to get their take profit value, instead of doing so, they captured 90002's!

Now in my code I don't call PositionSelect immediately before calling PositionInfoDouble, rather the last time is when the EA is checking if the operation changed from pending to running. When that happens, the internal structure with the operation info changes setting a flag to "Running" and since then, a switch-case makes the operation be processes by a manageNeg/PosOperation function. The idea here is that PositionSelect would 'keep active' till the position's end and thus I could call PositionInfoX at will without new calls to PositionSelect. 

The impression is that this is not happening, rather PositionSelect is putting the position info in some global way and, thus, when 40008 and 30008 called PositionInfoDouble, they got 90002's info since this was the last EA to call PositionSelect. 

Now my question is: is this the way PositionSelect is suppose to work? So I need to call it again and again every time before manageNeg/PosOperation()? Or is this a bug and 40008 and 30008 should have never got 90002's info?

Note: it may help to notice that I've worked with this EA for quite some time and this is not the first time I had consecutive operations running from different EAs, but it's the first time I see this error.

 

Function PositionSelect() copies data about a position into the program environment, and further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the earlier copied data. This means that the position itself may no longer exist (or its volume, direction, etc. has changed), but data of this position still can be obtained. To ensure receipt of fresh data about a position, it is recommended to call PositionSelect() right before referring to them.

Don't assume how it works, read the documentation.
Documentation on MQL5: Trade Functions / PositionGetDouble
Documentation on MQL5: Trade Functions / PositionGetDouble
  • www.mql5.com
The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. The position property must be of the double type. There are 2 variants of the function. 2...
 
Alain Verleyen:
Don't assume how it works, read the documentation.

Fine ^.^ But it's curious this behavirour never happened before despite no changes in my algorithm. I thought it could be a bug in recent versions =)

Reason: