From 15538e81f46deae709fcf6f777cf33e9410e653c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 7 Sep 2017 00:06:31 +0200 Subject: [PATCH 1/2] Updated PositionClose function (MT5) Type of the ticket argument changed to ulong, added optional argument: deviation --- MtApi5/MtApi5Client.cs | 5 +++-- mq5/MtApi5.mq5 | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 33bf084b..69482ad0 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -497,9 +497,10 @@ namespace MtApi5 ///Closes a position with the specified ticket. /// ///Ticket of the closed position. - public bool PositionClose(int ticket) + ///Maximal deviation from the current price (in points). + public bool PositionClose(ulong ticket, ulong deviation = ulong.MaxValue) { - var commandParameters = new ArrayList { ticket}; + var commandParameters = new ArrayList { ticket, deviation }; return SendCommand(Mt5CommandType.PositionClose, commandParameters); } diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index bc4e935a..b213a58e 100755 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -279,12 +279,14 @@ int executeCommand() case 64: //PositionClose { - int ticket; + ulong ticket; + ulong deviation; CTrade trade; - - getIntValue(ExpertHandle, 0, ticket); - - sendBooleanResponse(ExpertHandle, trade.PositionClose(ticket)); + + getULongValue(ExpertHandle, 0, ticket); + getULongValue(ExpertHandle, 1, deviation); + + sendBooleanResponse(ExpertHandle, trade.PositionClose(ticket, deviation)); } break; From d25fe529b4567acedcc692057d9409dd6b989fd6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 7 Sep 2017 00:21:12 +0200 Subject: [PATCH 2/2] Fixed warning in function CreateErrorResponse (MT5) Declaration of 'message' hides global declaration in MtApi5.mq5 --- mq5/MtApi5.mq5 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index b213a58e..453e2d05 100755 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -1908,7 +1908,7 @@ string OnRequest(string json) return response; } -string CreateErrorResponse(int code, string message) +string CreateErrorResponse(int code, string message_er) { JSONValue* jsonError; if (code == 0) @@ -1916,13 +1916,13 @@ string CreateErrorResponse(int code, string message) else jsonError = new JSONNumber((long)code); - JSONObject *joResponse = new JSONObject(); + JSONObject *joResponse = new JSONObject(); joResponse.put("ErrorCode", jsonError); - joResponse.put("ErrorMessage", new JSONString(message)); + joResponse.put("ErrorMessage", new JSONString(message_er)); - string result = joResponse.toString(); - delete joResponse; - return result; + string result = joResponse.toString(); + delete joResponse; + return result; } string CreateSuccessResponse(string responseName, JSONValue* responseBody)