diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj
index 30bc22a9..863ac787 100755
--- a/MtApi5/MtApi5.csproj
+++ b/MtApi5/MtApi5.csproj
@@ -71,10 +71,8 @@
-
-
-
-
+
+
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 193099b2..6bf350a9 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -116,13 +116,13 @@ namespace MtApi5
return false;
}
- var response = SendRequest(new OrderSendRequest
+ var response = SendRequest(new OrderSendRequest
{
TradeRequest = request
});
- result = response?.Value?.TradeResult;
- return response?.Value != null && response.Value.RetVal;
+ result = response?.TradeResult;
+ return response != null && response.RetVal;
}
///
@@ -1238,11 +1238,14 @@ namespace MtApi5
///
public List CopyTicks(string symbolName, CopyTicksFlag flags = CopyTicksFlag.All, ulong from = 0, uint count = 0)
{
- var response = SendRequest(new CopyTicksRequest
+ var response = SendRequest>(new CopyTicksRequest
{
- SymbolName = symbolName, Flags = (int)flags, From = from, Count = count
+ SymbolName = symbolName,
+ Flags = (int)flags,
+ From = from,
+ Count = count
});
- return response.Ticks;
+ return response;
}
#endregion
@@ -2178,7 +2181,7 @@ namespace MtApi5
///input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, double[] parameters)
{
- var response = SendRequest(new ICustomRequest
+ var response = SendRequest(new ICustomRequest
{
Symbol = symbol,
Timeframe = (int)period,
@@ -2186,7 +2189,7 @@ namespace MtApi5
Params = new ArrayList(parameters),
ParamsType = ICustomRequest.ParametersType.Double
});
- return response?.Value ?? 0;
+ return response;
}
///
@@ -2198,7 +2201,7 @@ namespace MtApi5
///input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, int[] parameters)
{
- var response = SendRequest(new ICustomRequest
+ var response = SendRequest(new ICustomRequest
{
Symbol = symbol,
Timeframe = (int)period,
@@ -2206,7 +2209,47 @@ namespace MtApi5
Params = new ArrayList(parameters),
ParamsType = ICustomRequest.ParametersType.Int
});
- return response?.Value ?? 0;
+ return response;
+ }
+
+ ///
+ ///The function returns the handle of the Volumes indicator.
+ ///
+ ///The symbol name of the security, the data of which should be used to calculate the indicator.
+ ///The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.
+ ///The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).
+ ///input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.
+ public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, string[] parameters)
+ {
+ var response = SendRequest(new ICustomRequest
+ {
+ Symbol = symbol,
+ Timeframe = (int)period,
+ Name = name,
+ Params = new ArrayList(parameters),
+ ParamsType = ICustomRequest.ParametersType.Int
+ });
+ return response;
+ }
+
+ ///
+ ///The function returns the handle of the Volumes indicator.
+ ///
+ ///The symbol name of the security, the data of which should be used to calculate the indicator.
+ ///The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.
+ ///The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).
+ ///input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.
+ public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, bool[] parameters)
+ {
+ var response = SendRequest(new ICustomRequest
+ {
+ Symbol = symbol,
+ Timeframe = (int)period,
+ Name = name,
+ Params = new ArrayList(parameters),
+ ParamsType = ICustomRequest.ParametersType.Int
+ });
+ return response;
}
#endregion // Public Methods
@@ -2400,7 +2443,7 @@ namespace MtApi5
return (T) responseValue;
}
- private T SendRequest(RequestBase request) where T : ResponseBase, new()
+ private T SendRequest(RequestBase request)
{
if (request == null)
return default(T);
@@ -2419,13 +2462,13 @@ namespace MtApi5
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
}
- var response = JsonConvert.DeserializeObject(res);
+ var response = JsonConvert.DeserializeObject>(res);
if (response.ErrorCode != 0)
{
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
}
- return response;
+ return response.Value;
}
diff --git a/MtApi5/Requests/OrderSendResult.cs b/MtApi5/Requests/OrderSendResult.cs
new file mode 100644
index 00000000..45e44f56
--- /dev/null
+++ b/MtApi5/Requests/OrderSendResult.cs
@@ -0,0 +1,8 @@
+namespace MtApi5.Requests
+{
+ internal class OrderSendResult
+ {
+ public bool RetVal { get; set; }
+ public MqlTradeResult TradeResult { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Responses/ResponseBase.cs b/MtApi5/Requests/Response.cs
old mode 100755
new mode 100644
similarity index 50%
rename from MtApi5/Responses/ResponseBase.cs
rename to MtApi5/Requests/Response.cs
index 2cf9f0e2..831aef4c
--- a/MtApi5/Responses/ResponseBase.cs
+++ b/MtApi5/Requests/Response.cs
@@ -1,8 +1,10 @@
-namespace MtApi5.Responses
+namespace MtApi5.Requests
{
- internal class ResponseBase
+ internal class Response
{
public int ErrorCode { get; set; }
public string ErrorMessage { get; set; }
+
+ public T Value { get; set; }
}
}
\ No newline at end of file
diff --git a/MtApi5/Responses/CopyTicksResponse.cs b/MtApi5/Responses/CopyTicksResponse.cs
deleted file mode 100755
index ab639e92..00000000
--- a/MtApi5/Responses/CopyTicksResponse.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace MtApi5.Responses
-{
- internal class CopyTicksResponse: ResponseBase
- {
- public List Ticks { get; set; }
- }
-}
\ No newline at end of file
diff --git a/MtApi5/Responses/ICustomResponse.cs b/MtApi5/Responses/ICustomResponse.cs
deleted file mode 100644
index aaaf864e..00000000
--- a/MtApi5/Responses/ICustomResponse.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// ReSharper disable InconsistentNaming
-namespace MtApi5.Responses
-{
- internal class ICustomResponse: ResponseBase
- {
- public int Value { get; set; }
- }
-}
diff --git a/MtApi5/Responses/OrderSendResponse.cs b/MtApi5/Responses/OrderSendResponse.cs
deleted file mode 100644
index f3a0a3ea..00000000
--- a/MtApi5/Responses/OrderSendResponse.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace MtApi5.Responses
-{
- internal class OrderSendResult
- {
- public bool RetVal { get; set; }
- public MqlTradeResult TradeResult { get; set; }
- }
-
- internal class OrderSendResponse: ResponseBase
- {
- public OrderSendResult Value { get; set; }
- }
-}
\ No newline at end of file
diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml
index c0cf3dff..5aedee1b 100755
--- a/TestClients/MtApi5TestClient/MainWindow.xaml
+++ b/TestClients/MtApi5TestClient/MainWindow.xaml
@@ -402,6 +402,12 @@
+
+
+
+
+
+
diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs
index 6aeb4233..1d47372c 100755
--- a/TestClients/MtApi5TestClient/ViewModel.cs
+++ b/TestClients/MtApi5TestClient/ViewModel.cs
@@ -55,6 +55,8 @@ namespace MtApi5TestClient
public DelegateCommand PositionOpenCommand { get; private set; }
public DelegateCommand PrintCommand { get; private set; }
+
+ public DelegateCommand iCustomCommand { get; private set; }
#endregion
#region Properties
@@ -237,6 +239,8 @@ namespace MtApi5TestClient
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
PrintCommand = new DelegateCommand(ExecutePrint);
+
+ iCustomCommand = new DelegateCommand(ExecuteICustom);
}
private bool CanExecuteConnect(object o)
@@ -832,6 +836,17 @@ namespace MtApi5TestClient
AddLog($"Print: message print in MetaTrader - {retVal}");
}
+ private async void ExecuteICustom(object o)
+ {
+ const string symbol = "EURUSD";
+ const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
+ const string name = @"Examples\Custom Moving Average";
+ int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
+
+ var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
+ AddLog($"Custom Moving Average: result - {retVal}");
+ }
+
private static void RunOnUiThread(Action action)
{
Application.Current?.Dispatcher.Invoke(action);
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index 7f4f8dd1..5993d1e7 100755
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index cb2bc99e..9bb80f5d 100755
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -5667,7 +5667,7 @@ string ExecuteRequest_CopyTicks(JSONObject *jo)
jaTicks.put(i, Serialize(ticks[i]));
}
- return CreateSuccessResponse("Ticks", jaTicks);;
+ return CreateSuccessResponse("Value", jaTicks);;
}
string ExecuteRequest_iCustom(JSONObject *jo)