How to close order partially at TP target

 

I think it's just posible to make it by using OrderComment or so, but no idea about how to do it.

This code close orders partially till exhausted:

if(Bid>OrderOpenPrice()+(OrderTakeProfit()-Breakeven)*(PartialClose2/100)){
        if(!OrderClose(OrderTicket(),OrderLots()*(PartialClose2/100),Bid,3,clr___)){
                Print("PartialClose error ",GetLastError());
                RefreshRates();
                return;
                }
                
        }

Hope someone can help to fix this issue.

 
Your lots must be a multiple of lotStep and between min and max.
 
William Roeder:
Your lots must be a multiple of lotStep and between min and max.

Ok, I can fix that with NormalizedDouble, buy how to close partially once at specified distance?

 
David Diez: I think it's just posible to make it by using OrderComment 
Can't modify comments
          Metaquotes language: OrderComment() is not able to be modified - Futures Trading - Expert Advisors and Automated Trading - MQL5 programming forum
Not a good idea to use comments, brokers can change comments, including complete replacement.
David Diez: Ok, I can fix that with NormalizedDouble, buy how to close partially once at specified distance?
That's easy, check if the market is at your "specified distance." The hard part is not doing it more than once — remembering that you already did the partial. Think:
  1. Changing your TP target.
  2. Check for SL at BE or better, and if not change it before the partial close.

As for NormalizeDouble, It's use is usually wrong, as it is in your case.

  1. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
              Double-precision floating-point format - Wikipedia, the free encyclopedia

    See also The == operand. - MQL4 programming forum

  2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

  3. SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
  4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
  5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - General - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
 
William Roeder:
Can't modify comments
          Metaquotes language: OrderComment() is not able to be modified - Futures Trading - Expert Advisors and Automated Trading - MQL5 programming forum
Not a good idea to use comments, brokers can change comments, including complete replacement. That's easy, check if the market is at your "specified distance." The hard part is not doing it more than once — remembering that you already did the partial. Think:
  1. Changing your TP target.
  2. Check for SL at BE or better, and if not change it before the partial close.

As for NormalizeDouble, It's use is usually wrong, as it is in your case.

  1. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
              Double-precision floating-point format - Wikipedia, the free encyclopedia

    See also The == operand. - MQL4 programming forum

  2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

  3. SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
  4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
  5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - General - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

But the case is that when you make a partial close manually in the MT terminal you can set any comment, and don't actually find the way to do it by MQL coding.

Then, changing TP target is not valid for this purpose from the point of partial close is taken from TP-OP distance, and TP is fixed.

Just realized that could be done by setting BE higher/lower tan OP, that could work. Thank you very much.

But still having the problema of keeping OrderComment() as defined at entry to keep an eye on stats.

Reason: