MQL5: Run Multiple Expert (with different MAGIC NUMBER) on same Symbol


Dear all,

I would like to run more Experts (with different MAGIC) on different charts but same symbol.

My doubt is management of open position. That is, I need to close the position of an EA when match some condition. See the following.

CPositionInfo     m_Position;        
CTrade            m_Trade;

int OnInit()
   int deviation=10;

void OnTick()
         if(condition_match && m_Position.Select(my_symbol))
            if(m_Position.PositionType()==POSITION_TYPE_SELL) m_Trade.PositionClose(my_symbol);
            if(m_Position.PositionType()==POSITION_TYPE_BUY) return;


Is that correct?

In other words I have EA#1 creating, for example, a position volume EURUSD of 0.1 Lots. Then EA#2 is making it's own trade, let's say 0.5 Lot EURUSD. I need the method for close exactly the position opened from EA#1 or EA#2.

MetaTrader 5 features hedging position accounting system
MetaTrader 5 features hedging position accounting system
  • 2016.03.21
  • MetaQuotes Software Corp.
The MetaTrader 5 platform was originally designed for trading within the netting position accounting system. The netting system allows having only one position per financial instrument meaning that all further operations at that instrument lead only to closing, reversal or changing the volume of the already existing position. In order to expand...
Hello friends,
I need your help.
I can get the magic number for the opened position, but if I want to open the second position in the same currency, how can I get the magic number for the second position?
For example, the first position to buy in the currency pair EURO-USD
And the second position for sell in the currency pair EURO-USD and of course in the same expert
Thanks a lot my friends.