[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 464

 
sss2019:
Can you tell me which function should close half of the order, OrderClose() or OrderCloseBy()?

If there is an open order and only part of it needs to be closed, it is sufficient to use OrderClose() with specifying the volume to be closed.
 
sss2019:
Can you tell me which function should close half of the order, OrderClose() or OrderCloseBy()?

Closing half of the order volume:

   int Ticket = ...
   OrderSelect(Ticket, SELECT_BY_TICKET);
   OrderClose(Ticket, NormalizeDouble(OrderLots()/2), Ask /*или Bid*/, Slippage);
 
MaxZ:

Close half of the order volume:


OrderSelect() before OrderClose() is not required.
 
PapaYozh:

OrderSelect() before OrderClose() is not required.
is required because it uses OrderLots
 
ilunga:
is required, as it uses OrderLots


In that case:

- first, we have to check the result returned by OrderSelect();

- Secondly, we need to keep an eye on the volume obtained in the process of division, or else it might not close at all.

 

PapaYozh, MaxZ The lot is 0.1, when calculating 30 ( ClosingPercent = 30) percentages should be 0.03, but error 131 occurs when closing with this lot.

           ClosingLot = OrderLots() / 100 * ClosingPercent;
           ClosingLot = NormalizeDouble(ClosingLot,3);
           OrderClose(OrderTicket(),ClosingLot,Ask,Slippage,Green);
 
sss2019:

PapaYozh, MaxZ The lot is 0.1, in the calculation of 30 ( ClosingPercent = 30) percentages should be 0.03, but error 131 occurs when closing with this lot.


Why do you normalize the volume to 3 digits?
 
sss2019:

PapaYozh, MaxZ It is 0.1 lot, when calculating 30 ( ClosingPercent = 30) percent should be 0.03, but error 131 occurs when closing with this lot

1) why normalize to 3 digits?

2) probably the minimum lot is 0.1 and then a smaller lot is in principle unavailable.

 
PapaYozh:

Why do you normalise the volume to 3 digits?

Well, if the lot is 0.10, you can't close 30%. But I tried to normalise to 2 digits with 1 lot and still the same error.
 
sss2019:

Well so if the lot is 0.10 then you can't close 30% already. But I've tried normalising to 2 digits with lot 1 and still the same error.

the digits are not counted as a whole, but after the decimal point.

i.e. normalising the number 10.044425 to 2 digits will result in the number 10.04


Yes, and where is your order selection before using OrderLots?