How to send a limit buy order in MT5?

To add comments, please log in or register

I placed a limit buy order using following code:


uint limitBuy(double amount, ulong magicNumber, double price, double tp, double sl) {
   printf("limit buying %G lot, at %G price, TP %G, SL %G", amount, price, tp, sl);
   MqlTradeRequest request = {0};
   request.action = TRADE_ACTION_DEAL; // or TRADE_ACTION_PENDING;
   request.type   = ORDER_TYPE_BUY_LIMIT;
   request.magic  = magicNumber;
   request.symbol = Symbol();
   request.volume = amount;
   request.price  = price;     = sl;     = tp;
   MqlTradeResult result = {0};

    if(!OrderSend(request,result)) {
      return 0; 
    //--- write the server reply to log  
    if(result.retcode==10016) Print(,result.ask,result.price);
    //--- return code of the trade server reply
    return result.retcode;   


the price crossed my limit price several times, but the order was not triggered. Is my above code correct to place a limit order?

I am placing order in strategy tester. If the code is correct, what other reason can result failing to execute the order?




To add comments, please log in or register