Error 130 by OrderSend only SELL

 

I have a buy order open and closed again.

Everything works




OrderNummer=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,NormalizeDouble(Bid-Sl*Point,Digits),NormalizeDouble(Bid+Tpf*Point,Digits),"Buy",123,0,Blue);




if(Bars > barsCount){

   if(OrdersTotal() > 0){

      for(int c = 0; c < OrdersTotal(); c++){

         OrderSelect(c, SELECT_BY_POS);

     

         if(OrderType() == OP_BUY){

            OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue);

         }else if(OrderType() == OP_SELL){

            OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);

         }

      }

    }

   

    barsCount = Bars;


}




When I open a SELL order comes the error 130





OrderNummer=OrderSend(Symbol(),OP_SELL,0.1,Ask,3,0,0,"SELL",123,0,Blue);


Even if I write



OrderNummer=OrderSend(Symbol(),OP_SELL,0.1,Ask,3,NormalizeDouble(Bid+Sl*Point,Digits),NormalizeDouble(Bid-Tpf*Point,Digits),"SELL",123,0,Blue);

The crazy is with a BUY order everything works only with SELL order comes the error

 
Uwe Schierz:

I have a buy order open and closed again.

OrderNummer=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,NormalizeDouble(Bid-Sl*Point,Digits),NormalizeDouble(Bid+Tpf*Point,Digits),"Buy",123,0,Blue);

if(Bars > barsCount){

   if(OrdersTotal() > 0){

      for(int c = 0; c < OrdersTotal(); c++){

         OrderSelect(c, SELECT_BY_POS);

     

         if(OrderType() == OP_BUY){

            OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue);

         }else if(OrderType() == OP_SELL){

            Order

The crazy is with a BUY order everything works only with SELL order comes the error


Hi, we can read your code better, and help, if you put your code to SRC ^̮^


 
Uwe Schierz: When I open a SELL order comes the error 130
  1. When you post code please use the SRC button !

  2. OrderNummer=OrderSend(Symbol(),OP_SELL,0.1,Ask,3,0,0,"SELL",123,0,Blue);
    You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  3. OrderNummer=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,NormalizeDouble(Bid-Sl*Point,Digits),NormalizeDouble(Bid+Tpf*Point,Digits),"Buy",123,0,Blue);
    Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

  4. Code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.

  5. if(Bars > barsCount){

    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.

  6.    if(OrdersTotal() > 0){
          for(int c = 0; c < OrdersTotal(); c++){
             OrderSelect(c, SELECT_BY_POS);
    
             if(OrderType() == OP_BUY){
                OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue);
    The if is unnecessary, no orders the loop does nothing.
  7. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) because while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
    2. For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    3. and check OrderSelect.
    4. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.
  8. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Reason: