title: MQL4 OrderCloseBy() returns error 3 == [ ERR_INVALID_TRADE_PARAMETERS ]
body: <p>I found this error and I am not sure about the reason ( The syntax is similar to C )</p>
  
  <p>The function is supposed to close a buy order with a sell order but I'm getting<br> <strong><code>error 3:</code></strong> <code>invalid trade parameters</code>.</p>
  
  <p><strong>Is there some parameter that I am setting wrong?</strong></p>
  
  <p>I have called before to <code>OrderClose()</code> successfully so I am guessing <code>OrderSend()</code> is correct.</p>
  
  <pre><code>void closeBuySell(int buyTicket){
     double buyPrice = OrderClosePrice();
     //Print("total ",OrdersTotal()," ",buyTickets," ",sellTickets);
     for(int Counter=0; Counter&lt;OrdersTotal(); Counter++){ //search for a matching sell
        if(OrderSelect(Counter,SELECT_BY_POS) &amp;&amp; OrderType()==OP_SELL &amp;&amp; OrderOpenPrice()&gt;buyPrice){
           Print("CLOSING BUYSELL ",buyTicket," ",OrderTicket()," ",OrderOpenPrice(),"&gt;",buyAsk);
           if(OrderCloseBy(buyTicket,OrderTicket(),Red)){ buyTickets--; sellTickets--; }
           else Print(ErrorDescription(GetLastError()));
           break;
        }
     }
  }
  
  int buyTickets=0;
  int sellTickets=0;
  bool up = false;
  void OnTick(){
     double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
     double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
     if(FastMA&gt;SlowMA &amp;&amp; !up){ up=true;
         if(buyTickets&lt;15 &amp;&amp; OrderSend(Symbol(),OP_BUY,.1,Ask,40,0,0))
             buyTickets++;
     }
     if(FastMA&lt;SlowMA &amp;&amp; up){ up=false;
         if(sellTickets&lt;15 &amp;&amp; OrderSend(Symbol(),OP_SELL,.1,Bid,40,0,0))
             sellTickets++;
     }
  
     for(int Counter=0; Counter&lt;OrdersTotal(); Counter++) //ordercloseby buy with sell
        if(OrderSelect(Counter,SELECT_BY_POS) &amp;&amp; OrderType()==OP_BUY)
            closeBuySell(OrderTicket());
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>...after
  13:42  practice1 EURUSD,M5: invalid trade parameters
  13:42  practice1 EURUSD,M5: OrderCloseBy error 3
  13:42  practice1 EURUSD,M5: CLOSING BUYSELL 17 8 1.086&gt;1.086
  13:40  practice1 EURUSD,M5: invalid trade parameters
  13:40  practice1 EURUSD,M5: OrderCloseBy error 3
  13:40  practice1 EURUSD,M5: CLOSING BUYSELL 23 1 1.0858&gt;1.0855
  13:40  practice1 EURUSD,M5: invalid trade parameters
  13:40  practice1 EURUSD,M5: OrderCloseBy error 3
  13:40  practice1 EURUSD,M5: CLOSING BUYSELL 22 1 1.0858&gt;1.0855
  00:05  practice1 EURUSD,M5: sell orders:12
  00:05  practice1 EURUSD,M5: open #12 sell limit 0.10 EURUSD at 1.08598 ok
  00:05  practice1 EURUSD,M5: sell orders:11
  00:05  practice1 EURUSD,M5: open #11 sell limit 0.10 EURUSD at 1.08599 ok
  00:05  practice1 EURUSD,M5: sell orders:10
  00:05  practice1 EURUSD,M5: open #10 sell limit 0.10 EURUSD at 1.08600 ok
  ...before
  </code></pre>