Partial Close detection

 

Dear community,

i have an EA which does partial close of position. I want to detect that a position has already been partialy closed and was checking the ordercomment for "split from " string. Now i have seen in other terminal this string may vary to "to #" "split #" etc.

What do you recommend how to detect a position has been already partically closed? One approach was to find history with same ENTRY price and time but is there a better way then this please?

regards

 
fx1.net:
i have an EA which does partial close of position. I want to detect that a position has already been partialy closed and was checking the ordercomment for "split from " string. Now i have seen in other terminal this string may vary to "to #" "split #" etc.

What do you recommend how to detect a position has been already partically closed? One approach was to find history with same ENTRY price and time but is there a better way then this please?

  1. Brokers can change comments, including complete replacement or none at all. Comments are unreliable, don't use them.
  2. Move the stop to BE or better and THEN do partial close.
 

Indeed comments are very unreliable. I have an EA which uses 4 time a partial close. All worked well with fixed lots because i knew when a part was closed. With applyed moneymanagement all this went to hell since there is no possible way to find out reliable how big was the initial order.

I changed the method. currently i open 4 orders (i use pendings so no problem here) which gives me the advantage of having 4 different stoplosses/trailings/takeprofits AND i can reliably check if one part is already closed

 
// determines if this position has partially exited yet
// use only with market trades!!!
bool PartialExitCheck(int t)
{   
   if (OrderSelect(t,SELECT_BY_TICKET))  
      {   
      //l("Partial Close Check for "+t,Red);     
      double EP = OrderOpenPrice();
      double DT = OrderOpenTime();
      double SL = OrderStopLoss();
      double TP = OrderTakeProfit();
      int T = OrderType(); 
      int L = OrderLots();
      if (T!=OP_BUY && T!=OP_SELL) return(false);
      int M = OrderMagicNumber();      
      string S = OrderSymbol();
      int D = MarketInfo(S,MODE_DIGITS);            
      
      for (int i=0; i<OrdersHistoryTotal();i++)
         {
         if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
         if (
            (OrderSymbol()==S) &&
            (OrderMagicNumber()==M) &&
            (NormalizeDouble(OrderOpenPrice(),D)==NormalizeDouble(EP,D)) &&
            (NormalizeDouble(OrderTakeProfit(),D)==NormalizeDouble(TP,D)) 
            && (OrderLots()<L)
            && (OrderOpenTime()==DT) 
            )
               {       
                  //l("   EP:"+DoubleToStr(EP,D),Yellow);
                  //l("   TP:"+DoubleToStr(TP,D),Yellow);
                  //l("MAGIC:"+DoubleToStr(M,0),Yellow);               
                  //l("PartialExit Match from "+t+" found by ticket: "+OrderTicket());
                  return(true);                   
               }                        
         }                            
      }
return(false);
}
for other people they may need something similar, this is my approach, its not safest way but in my EA it seems to work
Reason: