From 9d48f74b29f67fbbb76032b2c9120446361b6e1f Mon Sep 17 00:00:00 2001 From: Wesley Teixeira Date: Tue, 13 Sep 2016 09:03:55 -0400 Subject: [PATCH 1/2] Added PositionClose command to MT5 Api --- MtApi5/MtApi5Client.cs | 11 +++++++++++ MtApi5/MtCommandType.cs | 3 ++- mq5/MtApi5.mq5 | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 8dacc260..698a990d 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -475,6 +475,17 @@ namespace MtApi5 { return sendCommand(Mt5CommandType.OrderCloseAll, null); } + + /// + ///Closes a position with the specified ticket. + /// + ///Ticket of the closed position. + public bool PositionClose(int ticket) + { + var commandParameters = new ArrayList { ticket}; + + return sendCommand(Mt5CommandType.PositionClose, commandParameters); + } #endregion #region Account Information functions diff --git a/MtApi5/MtCommandType.cs b/MtApi5/MtCommandType.cs index bede832d..f9c6a41c 100755 --- a/MtApi5/MtCommandType.cs +++ b/MtApi5/MtCommandType.cs @@ -100,6 +100,7 @@ namespace MtApi5 MarketBookAdd = 60, MarketBookRelease = 61, MarketBookGet = 62, - OrderCloseAll = 63 + OrderCloseAll = 63, + PositionClose = 64 } } diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index 86dc224f..ac2a84ec 100755 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -227,6 +227,14 @@ int executeCommand() sendBooleanResponse(ExpertHandle, retVal); } break; + case 64: //PositionCloseBy + { + ulong ticket; + getULongValue(ExpertHandle, 0, ticket); + + sendBooleanResponse(ExpertHandle, PositionClose(ticket)); + } + break; case 2: // OrderCalcMargin { From 4258ff455115aeab73ddaa33485977fc26cd8294 Mon Sep 17 00:00:00 2001 From: Wesley Teixeira Date: Tue, 13 Sep 2016 10:03:16 -0400 Subject: [PATCH 2/2] Fixed Mql Script --- mq5/MtApi5.mq5 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index ac2a84ec..8969c5c8 100755 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -227,12 +227,14 @@ int executeCommand() sendBooleanResponse(ExpertHandle, retVal); } break; - case 64: //PositionCloseBy - { - ulong ticket; - getULongValue(ExpertHandle, 0, ticket); - - sendBooleanResponse(ExpertHandle, PositionClose(ticket)); + case 64: //PositionClose + { + int ticket; + CTrade trade; + + getIntValue(ExpertHandle, 0, ticket); + + sendBooleanResponse(ExpertHandle, trade.PositionClose(ticket)); } break; @@ -1734,4 +1736,4 @@ bool OrderCloseAll() if (trade.PositionClose(PositionGetSymbol(i))) i--; } return true; -} \ No newline at end of file +}