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

To add comments, please log in or register
sa.ca.mt5
13
sa.ca.mt5  

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

fxsaber
10581
fxsaber  
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...
To add comments, please log in or register