Send two orders at the same time

 
I want to send two crossed orders, buy in one asset and sell in other at the same time. How can I do that?
 
paulomoises: I want to send two crossed orders, buy in one asset and sell in other at the same time. How can I do that?

You can't send them at exactly the same time. They have to be send one after the other!

Assuming you are using MQL5, use the OrderSend() function (or CTrade class) once for each order request.

 
You can send orders asynchronously (same time/without blocking) in MT5 via the API, and you can also do it in MT4 by using separate charts to send the orders.  
 
nicholi shen: You can send orders asynchronously (same time/without blocking) in MT5 via the API, and you can also do it in MT4 by using separate charts to send the orders.  

You are just fudging the issue and complicate things for the OP! Even asynchronously you cannot send them at exactly the same time. And the same applies to MT4 EAs on separate charts.

 
Fernando Carreiro:

You are just fudging the issue and complicate things for the OP! Even asynchronously you cannot send them at exactly the same time. And the same applies to MT4 EAs on separate charts.

Can you send them in the same CPU clock cycle and in the same network packet in 4/5? No, obviously not. Can you send them in less than 1 ms of each other on both platforms? Absolutely. MT is a retail platform not HFT, so for all intensive purposes async is "same time".

 
paulomoises:
I want to send two crossed orders, buy in one asset and sell in other at the same time. How can I do that?

Forum on trading, automated trading systems and testing trading strategies

Libraries: TradeTransactions

Automated-Trading, 2018.10.25 18:37

// Example of massive asynchronous trade orders with waiting for a result.

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006
#include <fxsaber\TradeTransactions\TradeTransactions.mqh> // Access to OnTradeTransaction data anywhere in the program

TRADETRANSACTIONS Transactions; // Trading transactions

// Open Amount positions as quickly as possible. Return when positions are open.
bool OpenPositions( const int Amount = 10 )
{
  uint RequestID[];
  
  for (int i = ArrayResize(RequestID, Amount) - 1; i >= 0; i--)
  {
    const string Symb = SymbolName(i, true);
    
    RequestID[i] = OrderSendAsync(Symb, OP_BUY, 1, SymbolInfoDouble(Symb, SYMBOL_ASK), 100, 0, 0); // Send asynchronous order
  }
  
  return(Transactions.Waiting(RequestID)); // Wait for a server response to all asynchronous orders
}

// Close everything as quickly as possible. Return when the action is confirmed.
bool CloseAll()
{
  uint RequestID[];
  
  for (int i = ArrayResize(RequestID, OrdersTotal()) - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS))
      // Send asynchronous order
      RequestID[i] = (OrderType() <= OP_SELL) ? OrderCloseAsync(OrderTicket(), OrderLots(), OrderClosePrice(), 100) : OrderDeleteAsync(OrderTicket());
  
  return(Transactions.Waiting(RequestID)); // Wait for a server response to all asynchronous orders
}

void OnStart()
{
  if (OpenPositions())
    Print(CloseAll());
}