EA updates previous SL and TP when taking a new position on the same symbol (different lot sizes) with MT4

 

I am a US trader, so fifo applies.
Using MT4 with IG Broker (us).

Goal:

  • Take multiple long positions on EUR/USD
  • Different lot sizes each trade (to get around fifo)
  • Different stop loss and take profit for each trade

Issue:

  • New trades update previous trade SL & TP to the current trade
  • Previous trades should not  be modified

Trade execution function:

// Lots increments by 0.01 each trade so that lot sizes are never the same.
void orderOpen(int side,double Lots, double sl, double tp)
  {
   int ticket;
   if(side==1){
      ticket= OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,sl,tp,"Buy 1",01,0,Green);
      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
           {
            Print(OrderType()," first order opened : ",OrderOpenPrice());
            lastTradeTime=Time[0];
              }else{
            Print("Error opening BUY 1 order : ",GetLastError());
           }
           return;
        }
    }else if(side==-1){
      ticket= OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,sl,tp,"Sell 1",01,0,Red);
      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
           {
            Print(OrderType()," first order opened : ",OrderOpenPrice());
            lastTradeTime=Time[0];
              }else{
            Print("Error opening SELL 1 order : ",GetLastError());
           }
        }
     }
  }


I do not see any mention of my order being updated in the Journal:

2020.09.29 06:38:05.905    'x': order #98 buy 0.02 EURUSD.FX at 1.16704 closed due take-profit at price 1.17188
2020.09.29 06:38:05.905    'x': order #46 buy 0.01 EURUSD.FX at 1.16696 closed due take-profit at price 1.17188


2020.09.29 01:03:52.441    'x': order was opened : #98 buy 0.02 EURUSD.FX at 1.16704 sl: 1.16510 tp: 1.17188
2020.09.29 01:03:52.231    'x': instant order buy 0.02 EURUSD.FX at 1.16704 sl: 1.16510 tp: 1.17188


2020.09.28 23:00:22.939    'x': order was opened : #46 buy 0.01 EURUSD.FX at 1.16696 sl: 1.16521 tp: 1.17133
2020.09.28 23:00:22.710    'x': instant order buy 0.01 EURUSD.FX at 1.16696 sl: 1.16521 tp: 1.17133



Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Different lot sizes have nothing to do with FIFO.
  3. Some brokers make all TP/SL the same (due to FIFO). Open one order and do partial closes.
 
William Roeder:
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Different lot sizes have nothing to do with FIFO.
  3. Some brokers make all TP/SL the same (due to FIFO). Open one order and do partial closes.
  1. Sorry about that William, I didn't see an EA specific forum for MT4, so assumed it best fit here.
  2. Different lot sizes do get around fifo rules on some brokers. My Oanda account for instance allows for it.
  3. I just ran a test by hand on my IG account and can confirm that this is a broker issue, IG behaves as you describe. Thanks for pointing that out.
It seems I will need to move this particular EA to Oanda.
 
I will move your topic to the MQL4 and Metatrader 4 section.