Problem with market orders

 

Hello

I am having problems trying to get two orders to market at the same price range.

Sometimes it runs only Sell
Other times it runs only Buy

Sometimes running the two but less often than individually.

Do not know why this happens.

The code is this:

OrderSend(Symbol(),OP_BUY,0.10,Ask,20,1.3034,0,"My order #2",1,0,Green);

OrderSend(Symbol(),OP_SELL,0.10,Bid,20,1.3532,0,"My order #2",2,0,Green);

thanks for the answers

 
vulcano:

Hello

I am having problems trying to get two orders to market at the same price range.

Sometimes it runs only Sell
Other times it runs only Buy

Are you using a USA based Broker ? Hedging is not allowed in the USA.
 
RaptorUK:
Are you using a USA based Broker ? Hedging is not allowed in the USA.


My broker is alpari UK.

This allowed the hedging

Repeatedly executes the two orders, but I usually run only one

 
vulcano:


My broker is alpari UK.

This allowed the hedging

Repeatedly executes the two orders, but I usually run only one

What error code do you get from the failed trade ?

https://www.mql5.com/en/forum/138689

 
RaptorUK:

What error code do you get from the failed trade ?

https://www.mql5.com/en/forum/138689


RaptorUK
:

What error code do you get from the failed trade ?

https://www.mql5.com/en/forum/138689


It does not return any kind of error in the log

It appears as you have not already sent and
 
vulcano:

It does not return any kind of error in the log

It appears as you have not already sent and
Did you add the code to report the error to the log ?
 
RaptorUK:
Did you add the code to report the error to the log ?
Such as
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
 
WHRoeder:
Such as


ok. I will try it

 
vulcano:


ok. I will try it

If you had tried it when I suggested it you would already know what your issue is and have already fixed it . . .
 

The error returned is:

ERR_INVALID_PRICE129Invalid price.

How fix this error?

 
vulcano:

The error returned is:

ERR_INVALID_PRICE129Invalid price.

How fix this error?

Without seeing more of your code it is very hard to say why you are getting this error . . . . it is most likely that the Bid or Ask has become out of date . . . try adding a RefreshRates(); before the OrderSend() lines . . .
Reason: