How to add comment on close positions? - page 2

 

This could interest you, in next MT5 update :

Terminal: In the hedging mode, the ticket of a closed position is now displayed for the orders and deals in the trading history. This makes it easier to find related opening and closing operations.

List of changes in MetaTrader 5 Client Terminal builds
List of changes in MetaTrader 5 Client Terminal builds
  • www.mql5.com
See the "MQL5 Reference / Standard constants, enumerations and structures / Named constants / Other constants " section.
 
Alain Verleyen:

This could interest you, in next MT5 update :

Thanks Alain, is this update already out, what version is it? Please post the link, thanks.
 
arcull:
Thanks Alain, is this update already out, what version is it? Please post the link, thanks.
I posted the link, can't you see it in previous post ?
 
Yeah, sorry it looks like a banner ;) I overlooked it. Cool, the version is released tomorrow, thanks Alain
 
arcull:
Hi Nguyen and sorry for late reply. This is exactly what I need, I've tested and it works ok. However I will extend the CTrade class and reimplement the PositionClose methods, rather then changing the class definition directly. Thank you once again for your help. I owe you a beer ;)

How can overwrite this code?

bool CTrade::PositionClose(const ulong ticket,const ulong deviation)


?


p.s.

This solution is OK but I get compiler error:

'PositionClose' - function already defined and has body bolbands_joze_115h35.mq5 2866 14


 
Nguyen Nga #:

Hi

i get code below from CTrade, i add code about comment. you can comment anything when EA close position.

but can not if postion hit TP/SL. 

 

   m_request.comment  = PositionGetString(POSITION_COMMENT); // "Comment anything";

 

bool CTrade::PositionClose(const ulong ticket,const ulong deviation)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- check position existence
   if(!PositionSelectByTicket(ticket))
      return(false);
   string symbol=PositionGetString(POSITION_SYMBOL);
//--- clean
   ClearStructures();
//--- check
   if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
     {
      //--- prepare request for close BUY position
      m_request.type =ORDER_TYPE_SELL;
      m_request.price=SymbolInfoDouble(symbol,SYMBOL_BID);
     }
   else
     {
      //--- prepare request for close SELL position
      m_request.type =ORDER_TYPE_BUY;
      m_request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
     }
//--- setting request
   m_request.action   =TRADE_ACTION_DEAL;
   m_request.position =ticket;
   m_request.symbol   =symbol;
   m_request.volume   =PositionGetDouble(POSITION_VOLUME);
   m_request.magic    =m_magic;
   m_request.deviation=(deviation==ULONG_MAX) ? m_deviation : deviation;

   m_request.comment  = PositionGetString(POSITION_COMMENT); // "Comment anything";


//--- close position
   PrintFormat("PositionClose #%I64d %s %.2f",ticket,EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)),m_request.volume);
   return(OrderSend(m_request,m_result));
  }
Thank you very much, it solved my problem
Reason: