#define Expert_MagicNumber 12345 for(int i = PositionsTotal() - 1 ;i >= 0; i--) { if(PositionGetString(POSITION_SYMBOL) != _Symbol || PositionGetInteger(POSITION_MAGIC) != Expert_MagicNumber) continue; // ticket = PositionGetTicket(i); // if(!PositionSelectByTicket(ticket)) // continue; m_Trade.PositionClose(PositionGetTicket()); }
I think you have used the PositionSelectByTicket the wrong way.
Read this https://www.mql5.com/en/docs/trading/positionselectbyticket
Here is how I understand the document. Try this instead: (let me know if it is wrong also)

- www.mql5.com
I think you have used the PositionSelectByTicket the wrong way.
Read this https://www.mql5.com/en/docs/trading/positionselectbyticket
Here is how I understand the document. Try this instead: (let me know if it is wrong also)
I think you have used the PositionSelectByTicket the wrong way.
Read this https://www.mql5.com/en/docs/trading/positionselectbyticket
Here is how I understand the document. Try this instead: (let me know if it is wrong also)
for(int i = PositionsTotal() - 1 ; i >= 0; i--) { pos_ticket = PositionGetTicket(i); if( PositionSelectByTicket(pos_ticket) && (PositionGetString(POSITION_SYMBOL) == _Symbol) && (PositionGetInteger(POSITION_MAGIC) == Expert_MagicNumber) ) { // do stuff here } }
I ended up doing this, which works for my purposes. According to the docs, PositionGetTicket() requires an index value, returns the ticket for the position at that index, which is then used by PositionSelectByTicket().
In your code example, I think it's incorrect to use PositionGetTicket() without the index...
Anyway, thanks for the nudge in the right direction

- 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.
The situation: I have multiple copies of the same EA running on multiple pairs. I made this work by changing the name and magic number of each EA. The effect being, each is distinct from the other.
The issue: I thought the above would be enough to differentiate the trades made by each EA, but I'm seeing orders being canceled and positions being closed NOT in accordance to the strategy, and not in accordance with the correct operation of a single EA. It seems as though EA operations are clobbering each other
I have already tried using something like the following to check that an EA is operating only on the orders/positions it creates. This example uses "Position*", but the same construct holds for "Order*":
Besides the above, what steps | measures can I take, conditions can I check to make sure any given EA operates on only its orders/positions?
Note: I know there are better ways to trade on multiple pairs, i.e. multi-currency EAs, and that is on my development roadmap. Any resource recommendations to that effect are appreciated.
Thank you.