Inherit or set new trade-comment on partially closed trade using PositionClosePartial or alternative (Hedging Account)

 

Hi, I am working on Partial Closing Positions (MQL5). 

On A Netting account, I simply open an opposite order with the right volume,and can (of course) set the trade comment (Name of the EA) like with any other trade.

On a hedging account I use PostionTradePartial to partially close a position: 

m_trade.PositionClosePartial(PositionTicket,volume,deviation);

This works fine, StopLoss and TakeProfit are inherited, however not the comment.  The Comment section is empty. I have no clue how to manage to get the remaining position to have a trade-comment (either inherited or created new).  

bool  PositionClosePartial(
   const ulong   ticket,                  // Ticket der Position
   const double  volume,                  // Volumen
   ulong         deviation=ULONG_MAX      // Abweichung
   )


Does anyone no a solution to my problem? 


Thx 

 

Hallo,


mal dem chef zuvorkommen, hier wird deutsch gesprochen.


du hast 2 Möglichkeiten,

1) du setzt eine Hedge Order, nachteil natürlich der Spread

2) nachdem ich das nie verwende kann ich nicht sagen obs geht, du verwendest die Möglichkeit des CloseBy, da könnt ich mir vorstellen das es Möglichkeiten gibt


aber es gibt hier schlauere als mich


lg

 

was Du probieren könntest: folgende Zeile in der Funktion CTrade::PositionClosePartial der Trade.mqh-include-Datei hinzufügen (bin nicht sicher, ob es so funktioniert, da sich die Order ja auf den zu schließenden Anteil der Position bezieht und nicht auf die verbleibende Position, ist aber den Versuch wert --> sag Bescheid ob's damit funktioniert hat):

bool CTrade::PositionClosePartial(const string symbol,const double volume,const ulong deviation)
  {
   uint retcode=TRADE_RETCODE_REJECT;
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- for hedging mode only
   if(!IsHedging())
      return(false);
//--- clean
   ClearStructures();
//--- check filling
   if(!FillingCheck(symbol))
      return(false);
//--- check
   if(SelectPosition(symbol))
     {
      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);
        }
     }
   else
     {
      //--- position not found
      m_result.retcode=retcode;
      return(false);
     }
//--- check volume
   double position_volume=PositionGetDouble(POSITION_VOLUME);
   if(position_volume>volume)
      position_volume=volume;
//--- setting request
   m_request.comment  =PositionGetString(POSITION_COMMENT);
   m_request.action   =TRADE_ACTION_DEAL;
   m_request.symbol   =symbol;
   m_request.volume   =position_volume;
   m_request.magic    =m_magic;
   m_request.deviation=(deviation==ULONG_MAX) ? m_deviation : deviation;
   m_request.position =PositionGetInteger(POSITION_TICKET);
//--- hedging? just send order
   return(OrderSend(m_request,m_result));
  }
 

Geilo! 

Ja damit wird der Comment tatsaechlich vererbt. Merci.

 

Na dann: gern geschehen und willkommen im Forum (sehe, Du bist neu registriert).

Eine Sache in dem Kontext noch: bei Veränderungen an einer Standard-include-Datei wie Trade.mqh würde ich erwägen, eine umbenannte Version zu verwenden, damit die eigenen Veränderungen nicht bei jedem automatischen Update überschrieben werden.

 
Chris70:

Na dann: gern geschehen und willkommen im Forum (sehe, Du bist neu registriert).

Eine Sache in dem Kontext noch: bei Veränderungen an einer Standard-include-Datei wie Trade.mqh würde ich erwägen, eine umbenannte Version zu verwenden, damit die eigenen Veränderungen nicht bei jedem automatischen Update überschrieben werden.

Danke, ja das hab ich auch gemacht;-)
 
waxwell:

Geilo! 

Ja damit wird der Comment tatsaechlich vererbt. Merci.

Ja, das funktioniert. Genau bis zum nächsten Zwangsupdate. 

Fazit: Nicht in der Systemlibrary umfummeln sonder eigene Klassen ableiten!

Grund der Beschwerde: