Closing order at market price

 

Hello,

I have had an interesting failure in my EA recently when closing the order that I have never seen before. The function as everyone knows is this

bool  OrderClose(
   int        ticket,      // ticket
   double     lots,        // volume
   double     price,       // close price
   int        slippage,    // slippage
   color      arrow_color  // color
   );

Close price  must be the current Bid price for closing a BUY order or the current Ask price for closing a SELL order.

In my case the call failed because the price was 0.0. Was some reason Bid returned 0.

This leads me to the question - Why the call has price parameter at all? If I want to close at the market price I should not supply the price. Is it because the same call can handle both Market and Limit order Close?

Thank you

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Viktor Iassinskii: Is it because the same call can handle both Market and Limit order Close?

    You close opened orders. Limit and stops are pending orders, you don't close them, you delete them.

  2. Viktor Iassinskii: In my case the call failed because the price was 0.0. Was some reason Bid returned 0.

    No idea how that could be possible. In any case, you could have just used OrderClosePrice() and be direction and symbol independent.

  3. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time, post in the correct place. The moderators will likely move this thread there soon.

 
William Roeder 
  1. No idea how that could be possible. In any case, you could have just used OrderClosePrice() and be direction and symbol 

To use OrderClosePrice() to close his trade? He is asking why his Bid returned 0,0… and why he needs to put price in CloseOrder function…. 
 
I will say that sometimes there is a glitch in the sys … maybe during rollover … I would include a “ retry” to the CloseOrder()… if it fails to close sleep for 1 sec… and try again… 😊
 
Viktor Iassinskii:

Hello,

I have had an interesting failure in my EA recently when closing the order that I have never seen before. The function as everyone knows is this

Close price  must be the current Bid price for closing a BUY order or the current Ask price for closing a SELL order.

In my case the call failed because the price was 0.0. Was some reason Bid returned 0.

This leads me to the question - Why the call has price parameter at all? If I want to close at the market price I should not supply the price. Is it because the same call can handle both Market and Limit order Close?

Thank you

Show your actual code if you want an answer about why "the price was 0.0".

There is a close price because it can be used to control slippage, in some circumstances (market maker brokers and symbol allowing it).

Reason: