Open Simultaneous Orders with different Magic Number on same EA

 

I am trying to open 2 orders in my EA ( Same chart at Same time )

Reason : One order use Take Profit amount and the other one do not set Take Profit amount ( I set this to 0 ) as this order will do trailing stop later.

I used 2 different MagicNumbers to differentiate the orders. 

However, when I run EA on the strategy tester it opens only one order.

Can some one help me to fix this.

//------------   Order #1   -------------- 
//----------------------------------------

   void BuyOrder()
   {
      if (OrdersTotal() == 0)
      {
         double StopLoss = StopLoss();
         double TakeProfit = TakeProfit();       
         int Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, Bid-StopLoss, Bid+TakeProfit, "BUY order", MagicNumber1);
         Comment ("BUY Order #1 Placed");
      }
   }
//------------  Order #2  -------------- 
//--------------------------------------

   void SecondBuyOrder()
   {
      if (OrdersTotal() == 0)
      {
         double StopLoss = StopLoss();
         double TakeProfit =  TakeProfit();
         int Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, Bid-StopLoss, 0, "BUY order", MagicNumber2);
         Comment ("BUY Order #2 Placed");
      }
   }

//-------- On Tick Function -------
//---------------------------------

void OnTick()
  {
    if (OrdersTotal() == 0)
    {  
      if ( Signal() == "LONG") 
      {
         BuyOrder();
         SecondBuyOrder();
      }
      else if (Signal() == "SHORT")
      {
         SellOrder();       
         SecondSellOrder();
      }
    }
 
imalkaiw:

I am trying to open 2 orders in my EA ( Same chart at Same time )

Reason : One order use Take Profit amount and the other one do not set Take Profit amount ( I set this to 0 ) as this order will do trailing stop later.

I used 2 different MagicNumbers to differentiate the orders. 

However, when I run EA on the strategy tester it opens only one order.

Can some one help me to fix this.

Pretty obvious, you cannot have this line in both BuyOrder() and SecondBuyOrder():

OrdersTotal() == 0

Since after BuyOrder() this check will return 1, so your SecondBuyOrder() will never get to open any new order.

Perhaps you can change the one in SecondBuyOrder() to:

OrdersTotal() == 1
 
Seng Joo Thio:

Pretty obvious, you cannot have this line in both BuyOrder() and SecondBuyOrder():

Since after BuyOrder() this check will return 1, so your SecondBuyOrder() will never get to open any new order.

Perhaps you can change the one in SecondBuyOrder() to:

Thank you, This helped to solve the issue :)
Reason: