Problem with OrderClose

 

Hi,

when use OrderClose, always close also if not reach specific price. So must close when reach -/+100 points depends of direction.


My code:

   double ClosePrice = NormalizeDouble(MarketInfo(_Symbol,MODE_BID)-100*MarketInfo(_Symbol,MODE_POINT),(int)MarketInfo(_Symbol,MODE_DIGITS));
        if(OrderType() == OP_SELL) ClosePrice = NormalizeDouble(MarketInfo(_Symbol, MODE_ASK)+100*MarketInfo(_Symbol,MODE_POINT),(int)MarketInfo(_Symbol,MODE_DIGITS));
        
           OrderClose(getFirstOpenTicketId(),OrderLots(),ClosePrice,Slippage,Red);
 

Use OrderModify if you want to change the takeprofit price or stoploss price.


bool  OrderModify(
   int        ticket,      // ticket
   double     price,       // price
   double     stoploss,    // stop loss
   double     takeprofit,  // take profit
   datetime   expiration,  // expiration
   color      arrow_color  // color
   );

EDIT: since you're calculating your own takeprofit / stoploss, you must normalize the price before entering it as a parameter in OrderModify. You're already doing that with NormalizeDouble, but it's better to use a custom function.

Read #1 in this link: https://www.mql5.com/en/forum/137301#comment_3474196

OrderModify - Trade Functions - MQL4 Reference
OrderModify - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderModify - Trade Functions - MQL4 Reference
 
Alexander Martinez #:

Use OrderModify if you want to change the takeprofit price or stoploss price.


EDIT: since you're calculating your own takeprofit / stoploss, you must normalize the price before entering it as a parameter in OrderModify. You're already doing that with NormalizeDouble, but it's better to use a custom function.

Read #1 in this link: https://www.mql5.com/en/forum/137301#comment_3474196

thanks!

 

I dont think this will work
OrderClose(getFirstOpenTicketId(),OrderLots(),ClosePrice,Slippage,Red);

We should close at Bid or Ask, depending on the direction right? Or if you use OrderSelect() when closing your orders, can use OrderClosePrice().