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()
{
..
..
   m_Trade.SetExpertMagicNumber(EA_Magic);
   int deviation=10;
   m_Trade.SetDeviationInPoints(deviation);
   m_Trade.SetTypeFilling(ORDER_FILLING_RETURN);
   m_Trade.LogLevel(1);
   m_Trade.SetAsyncMode(true);
}

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.

Thanks

 
https://www.mql5.com/en/articles/2299
MetaTrader 5 features hedging position accounting system
MetaTrader 5 features hedging position accounting system
  • 2016.03.21
  • MetaQuotes Software Corp.
  • www.mql5.com
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.
Reason: