diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs
index a4062881..c50d5521 100755
--- a/MtApi5/Mt5CommandType.cs
+++ b/MtApi5/Mt5CommandType.cs
@@ -102,6 +102,8 @@ namespace MtApi5
PositionClose = 64,
PositionOpen = 65,
PositionModify = 6066,
+ PositionClosePartial_bySymbol = 6067,
+ PositionClosePartial_byTicket = 6068,
//PositionOpenWithResult = 1065,
//Backtesting
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 67eeca40..dfe730e4 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -655,6 +655,34 @@ namespace MtApi5
{
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
}
+
+ ///
+ /// Partially closes a position on a specified symbol in case of a "hedging" accounting.
+ ///
+ /// Name of a trading instrument, on which a position is closed partially.
+ /// Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.
+ /// The maximum deviation from the current price (in points).
+ /// true if the basic check of structures is successful, otherwise false.
+ public bool PositionClosePartial(string symbol, double volume, ulong deviation = ulong.MaxValue)
+ {
+ var commandParameters = new ArrayList { symbol, volume, deviation };
+
+ return SendCommand(Mt5CommandType.PositionClosePartial_bySymbol, commandParameters);
+ }
+
+ ///
+ /// Partially closes a position on a specified symbol in case of a "hedging" accounting.
+ ///
+ /// Closed position ticket.
+ /// Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.
+ /// The maximum deviation from the current price (in points).
+ /// true if the basic check of structures is successful, otherwise false.
+ public bool PositionClosePartial(ulong ticket, double volume, ulong deviation = ulong.MaxValue)
+ {
+ var commandParameters = new ArrayList { ticket, volume, deviation };
+
+ return SendCommand(Mt5CommandType.PositionClosePartial_byTicket, commandParameters);
+ }
#endregion
#region Account Information functions
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index d7a4a77e..cffcd207 100644
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index ad6c81b1..67361bcc 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -572,6 +572,12 @@ int executeCommand()
case 6066: //PositionModify
Execute_PositionModify();
break;
+ case 6067: //PositionClosePartial_bySymbol
+ Execute_PositionClosePartial_bySymbol();
+ break;
+ case 6068: //Execute_PositionClosePartial_byTicket
+ Execute_PositionClosePartial_byTicket();
+ break;
case 66: //BacktestingReady
Execute_BacktestingReady();
break;
@@ -3313,6 +3319,80 @@ void Execute_PositionModify()
}
}
+void Execute_PositionClosePartial_bySymbol()
+{
+ string symbol;
+ double volume;
+ ulong deviation;
+
+ if (!getStringValue(ExpertHandle, 0, symbol, _error))
+ {
+ PrintParamError("PositionClosePartial (1)", "symbol", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+ if (!getDoubleValue(ExpertHandle, 1, volume, _error))
+ {
+ PrintParamError("PositionClosePartial (1)", "volume", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+ if (!getULongValue(ExpertHandle, 2, deviation, _error))
+ {
+ PrintParamError("PositionClosePartial (1)", "deviation", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+
+ CTrade trade;
+ bool ok = trade.PositionClosePartial(symbol, volume, deviation);
+#ifdef __DEBUG_LOG__
+ Print("command PositionClosePartial (1): result = ", ok);
+#endif
+
+ if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
+ {
+ PrintResponseError("PositionClosePartial (1)", _response_error);
+ }
+}
+
+void Execute_PositionClosePartial_byTicket()
+{
+ ulong ticket;
+ double volume;
+ ulong deviation;
+
+ if (!getULongValue(ExpertHandle, 0, ticket, _error))
+ {
+ PrintParamError("PositionClosePartial (2)", "ticket", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+ if (!getDoubleValue(ExpertHandle, 1, volume, _error))
+ {
+ PrintParamError("PositionClosePartial (2)", "volume", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+ if (!getULongValue(ExpertHandle, 2, deviation, _error))
+ {
+ PrintParamError("PositionClosePartial (2)", "deviation", _error);
+ sendErrorResponse(ExpertHandle, -1, _error, _response_error);
+ return;
+ }
+
+ CTrade trade;
+ bool ok = trade.PositionClosePartial(ticket, volume, deviation);
+#ifdef __DEBUG_LOG__
+ Print("command PositionClosePartial (2): result = ", ok);
+#endif
+
+ if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
+ {
+ PrintResponseError("PositionClosePartial (2)", _response_error);
+ }
+}
+
void Execute_PositionOpen(bool isTradeResultRequired)
{
string symbol;