diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs
index bde25f2d..3ffd8dbc 100755
--- a/MtApi5/Mt5CommandType.cs
+++ b/MtApi5/Mt5CommandType.cs
@@ -250,6 +250,7 @@ namespace MtApi5
GlobalVariablesDeleteAll = 157,
GlobalVariablesTotal = 158,
- UnlockTicks = 159
+ UnlockTicks = 159,
+ PositionCloseAll = 160
}
}
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 1e6aee78..d788afdf 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -521,11 +521,20 @@ namespace MtApi5
///
///Close all open positions.
///
+ [Obsolete("OrderCloseAll is deprecated, please use PositionCloseAll instead.")]
public bool OrderCloseAll()
{
return SendCommand(Mt5CommandType.OrderCloseAll, null);
}
+ ///
+ ///Close all open positions. Returns count of closed positions.
+ ///
+ public int PositionCloseAll()
+ {
+ return SendCommand(Mt5CommandType.PositionCloseAll, null);
+ }
+
///
///Closes a position with the specified ticket.
///
diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml
index b9383780..996cd4ec 100755
--- a/TestClients/MtApi5TestClient/MainWindow.xaml
+++ b/TestClients/MtApi5TestClient/MainWindow.xaml
@@ -486,6 +486,7 @@
+
@@ -493,6 +494,7 @@
+
diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs
index 971dd8d2..ec356a87 100755
--- a/TestClients/MtApi5TestClient/ViewModel.cs
+++ b/TestClients/MtApi5TestClient/ViewModel.cs
@@ -67,6 +67,7 @@ namespace MtApi5TestClient
public DelegateCommand PositionOpenCommand { get; private set; }
public DelegateCommand PositionCloseCommand { get; private set; }
+ public DelegateCommand PositionCloseAllCommand { get; private set; }
public DelegateCommand GetLastErrorCommand { get; private set; }
public DelegateCommand ResetLastErrorCommand { get; private set; }
@@ -375,6 +376,7 @@ namespace MtApi5TestClient
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
PositionCloseCommand = new DelegateCommand(ExecutePositionClose);
+ PositionCloseAllCommand = new DelegateCommand(ExecutePositionCloseAll);
PrintCommand = new DelegateCommand(ExecutePrint);
AlertCommand = new DelegateCommand(ExecuteAlert);
@@ -1126,6 +1128,12 @@ namespace MtApi5TestClient
AddLog($"PositionClose: ticket {ticket} retVal = {retVal}, result = {tradeResult}");
}
+ private async void ExecutePositionCloseAll(object obj)
+ {
+ var retVal = await Execute(() => _mtApiClient.PositionCloseAll());
+ AddLog($"PositionCloseAll: count = {retVal}");
+ }
+
private async void ExecutePrint(object obj)
{
var message = MessageText;
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index a5cc4ad3..df9f80a7 100755
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index 5d20ccb0..8a0f86ab 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -791,6 +791,9 @@ int executeCommand()
case 159: //UnlockTiks
Execute_UnlockTicks();
break;
+ case 160: //PositionCloseAll
+ Execute_PositionCloseAll();
+ break;
case 204: //TerminalInfoInteger
Execute_TerminalInfoInteger();
break;
@@ -6527,6 +6530,17 @@ void Execute_UnlockTicks()
}
}
+void Execute_PositionCloseAll()
+{
+ int res = PositionCloseAll();
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: result = %d", __FUNCTION__, res);
+#endif
+
+ SEND_INT_RESPONSE(res)
+}
+
void Execute_TerminalInfoInteger()
{
int propertyId;
@@ -6714,6 +6728,18 @@ bool OrderCloseAll()
return true;
}
+int PositionCloseAll()
+{
+ CTrade trade;
+ int total = PositionsTotal();
+ int i = total -1;
+ while (i >= 0)
+ {
+ if (trade.PositionClose(PositionGetSymbol(i))) i--;
+ }
+ return total;
+}
+
//------------ Requests -------------------------------------------------------
string OnRequest(string json)
@@ -7408,10 +7434,6 @@ private:
void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
{
-#ifdef __DEBUG_LOG__
- PrintFormat("%s: eventType = %d", __FUNCTION__, eventType);
-#endif
-
JSONObject* json = mtEvent.CreateJson();
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
{