diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs
index 87d809b4..522a6d8c 100755
--- a/MtApi5/Mt5CommandType.cs
+++ b/MtApi5/Mt5CommandType.cs
@@ -187,8 +187,8 @@ namespace MtApi5
ChartApplyTemplate = 236,
ChartSaveTemplate = 237,
ChartWindowFind = 238,
- ChartTimePriceToXY = 239,
- ChartXYToTimePrice = 240,
+ //ChartTimePriceToXY = 239,
+ //ChartXYToTimePrice = 240,
ChartOpen = 241,
ChartFirst = 242,
ChartNext = 243,
diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj
index ec727208..286efa50 100755
--- a/MtApi5/MtApi5.csproj
+++ b/MtApi5/MtApi5.csproj
@@ -73,6 +73,10 @@
+
+
+
+
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 4919acfc..cdf43c96 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -1578,22 +1578,17 @@ namespace MtApi5
///
public bool ChartTimePriceToXY(long chartId, int subWindow, DateTime? time, double price, out int x, out int y)
{
- var commandParameters = new ArrayList { chartId, subWindow, Mt5TimeConverter.ConvertToMtTime(time), price };
- var str = SendCommand(Mt5CommandType.ChartTimePriceToXY, commandParameters);
- var res = false;
- x = 0;
- y = 0;
- if (!string.IsNullOrEmpty(str) && str.Contains(";"))
- {
- var values = str.Split(';');
- if (values.Length > 1)
+ var result = SendRequest(new ChartTimePriceToXyRequest
{
- int.TryParse(values[0], out x);
- int.TryParse(values[1], out y);
- res = true;
- }
- }
- return res;
+ ChartId = chartId,
+ SubWindow = subWindow,
+ Time = time,
+ Price = price
+ });
+
+ x = result?.X ?? 0;
+ y = result?.Y ?? 0;
+ return result?.RetVal ?? false;
}
///
@@ -1610,26 +1605,17 @@ namespace MtApi5
///
public bool ChartXYToTimePrice(long chartId, int x, int y, out int subWindow, out DateTime? time, out double price)
{
- var commandParameters = new ArrayList { chartId, x, y };
- var str = SendCommand(Mt5CommandType.ChartXYToTimePrice, commandParameters);
- var res = false;
- subWindow = 0;
- time = null;
- price = double.NaN;
- if (!string.IsNullOrEmpty(str) && str.Contains(";"))
+ var result = SendRequest(new ChartXyToTimePriceRequest
{
- var values = str.Split(';');
- if (values.Length > 2)
- {
- int.TryParse(values[0], out subWindow);
- int mt4Time;
- int.TryParse(values[1], out mt4Time);
- time = Mt5TimeConverter.ConvertFromMtTime(mt4Time);
- double.TryParse(values[2], out price);
- res = true;
- }
- }
- return res;
+ ChartId = chartId,
+ X = x,
+ Y = y
+ });
+
+ subWindow = result?.SubWindow ?? 0;
+ time = result?.Time;
+ price = result?.Price ?? double.NaN;
+ return result?.RetVal ?? false;
}
///
diff --git a/MtApi5/Requests/ChartTimePriceToXyRequest.cs b/MtApi5/Requests/ChartTimePriceToXyRequest.cs
new file mode 100644
index 00000000..7287a2e5
--- /dev/null
+++ b/MtApi5/Requests/ChartTimePriceToXyRequest.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace MtApi5.Requests
+{
+ internal class ChartTimePriceToXyRequest : RequestBase
+ {
+ public override RequestType RequestType => RequestType.ChartTimePriceToXY;
+
+ public long ChartId { get; set; }
+ public int SubWindow { get; set; }
+ public DateTime? Time { get; set; }
+ public double Price { get; set; }
+
+ public int MtTime => Mt5TimeConverter.ConvertToMtTime(Time);
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Requests/ChartTimePriceToXyResult.cs b/MtApi5/Requests/ChartTimePriceToXyResult.cs
new file mode 100644
index 00000000..4c74ee20
--- /dev/null
+++ b/MtApi5/Requests/ChartTimePriceToXyResult.cs
@@ -0,0 +1,9 @@
+namespace MtApi5.Requests
+{
+ internal class ChartTimePriceToXyResult
+ {
+ public bool RetVal { get; set; }
+ public int X { get; set; }
+ public int Y { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Requests/ChartXyToTimePriceRequest.cs b/MtApi5/Requests/ChartXyToTimePriceRequest.cs
new file mode 100644
index 00000000..871f6aae
--- /dev/null
+++ b/MtApi5/Requests/ChartXyToTimePriceRequest.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace MtApi5.Requests
+{
+ internal class ChartXyToTimePriceRequest : RequestBase
+ {
+ public override RequestType RequestType => RequestType.ChartXYToTimePrice;
+
+ public long ChartId { get; set; }
+ public int X { get; set; }
+ public int Y { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Requests/ChartXyToTimePriceResult.cs b/MtApi5/Requests/ChartXyToTimePriceResult.cs
new file mode 100644
index 00000000..dfd3f1d4
--- /dev/null
+++ b/MtApi5/Requests/ChartXyToTimePriceResult.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace MtApi5.Requests
+{
+ internal class ChartXyToTimePriceResult
+ {
+ public bool RetVal { get; set; }
+ public int SubWindow { get; set; }
+ public DateTime? Time => Mt5TimeConverter.ConvertFromMtTime(MtTime);
+ public double Price { get; set; }
+
+ public int MtTime { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Requests/RequestType.cs b/MtApi5/Requests/RequestType.cs
index 1ba9024c..d0ac6c5a 100755
--- a/MtApi5/Requests/RequestType.cs
+++ b/MtApi5/Requests/RequestType.cs
@@ -12,6 +12,8 @@ namespace MtApi5.Requests
OrderCheck = 5,
MarketBookGet = 6,
IndicatorCreate = 7,
- SymbolInfoString = 8
+ SymbolInfoString = 8,
+ ChartTimePriceToXY = 9,
+ ChartXYToTimePrice = 10
}
}
\ No newline at end of file
diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml
index 65d502a7..9b5cb2d4 100755
--- a/TestClients/MtApi5TestClient/MainWindow.xaml
+++ b/TestClients/MtApi5TestClient/MainWindow.xaml
@@ -480,12 +480,29 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs
index 895bfc1b..4978dc47 100755
--- a/TestClients/MtApi5TestClient/ViewModel.cs
+++ b/TestClients/MtApi5TestClient/ViewModel.cs
@@ -76,6 +76,8 @@ namespace MtApi5TestClient
public DelegateCommand TimeCurrentCommand { get; private set; }
public DelegateCommand ChartOpenCommand { get; private set; }
+ public DelegateCommand ChartTimePriceToXYCommand { get; private set; }
+ public DelegateCommand ChartXYToTimePriceCommand { get; private set; }
public DelegateCommand ChartApplyTemplateCommand { get; private set; }
public DelegateCommand ChartSaveTemplateCommand { get; private set; }
@@ -88,15 +90,19 @@ namespace MtApi5TestClient
private async void ExecuteChartOpen(object o)
{
AddLog("Executed #1");
- if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
+ if (string.IsNullOrEmpty(ChartFunctionsSymbolValue))
+ {
+ AddLog("ChartOpen [ERROR]: Symbol is not defined!");
+ return;
+ }
- AddLog($"Executed #2 s:{TimeSeriesValues?.SymbolValue}");
+ AddLog($"Executed #2 s:{ChartFunctionsSymbolValue}");
var result = await Execute(() =>
{
- var SymbolAddReturn = _mtApiClient.SymbolSelect(TimeSeriesValues?.SymbolValue, true);
- var ChartId = _mtApiClient.ChartOpen(TimeSeriesValues?.SymbolValue, TimeSeriesValues.TimeFrame);
+ var SymbolAddReturn = _mtApiClient.SymbolSelect(ChartFunctionsSymbolValue, true);
+ var ChartId = _mtApiClient.ChartOpen(ChartFunctionsSymbolValue, TimeSeriesValues.TimeFrame);
return ChartId;
});
@@ -109,6 +115,45 @@ namespace MtApi5TestClient
AddLog($"ChartOpen: success chartid=>{result}");
}
+ private async void ExecuteChartTimePriceToXY(object o)
+ {
+ const long chartId = 0;
+ const int subWindow = 0;
+ var time = DateTime.Now;
+ const double price = 1.131;
+ var x = 0;
+ var y = 0;
+
+ var result = await Execute(() => _mtApiClient.ChartTimePriceToXY(chartId, subWindow, time, price, out x, out y));
+ if (result == false)
+ {
+ AddLog("ChartTimePriceToXY: result is false");
+ return;
+ }
+
+ AddLog($"ChartTimePriceToXY: success. x = {x}; Y = {y}");
+ }
+
+ private async void ExecuteChartXYToTimePrice(object o)
+ {
+ const long chartId = 0;
+ const int x = 0;
+ const int y = 0;
+
+ var subWindow = 0;
+ DateTime? time = null;
+ double price = double.NaN;
+
+ var result = await Execute(() => _mtApiClient.ChartXYToTimePrice(chartId, x, y, out subWindow, out time, out price));
+ if (result == false)
+ {
+ AddLog("ChartXYToTimePrice: result is false");
+ return;
+ }
+
+ AddLog($"ChartXYToTimePrice: success. subWindow = {subWindow}; time = {time}; price = {price}");
+ }
+
private async void ExecuteChartApplyTemplate(object o)
{
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
@@ -271,6 +316,16 @@ namespace MtApi5TestClient
}
}
+ private string _chartFunctionsSymbolValue = "EURUSD";
+ public string ChartFunctionsSymbolValue
+ {
+ get { return _chartFunctionsSymbolValue; }
+ set
+ {
+ _chartFunctionsSymbolValue = value;
+ OnPropertyChanged("ChartFunctionsSymbolValue");
+ }
+ }
#endregion
#region Public Methods
@@ -376,6 +431,8 @@ namespace MtApi5TestClient
iCustomCommand = new DelegateCommand(ExecuteICustom);
ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
+ ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
+ ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
ChartApplyTemplateCommand = new DelegateCommand(ExecuteChartApplyTemplate);
ChartSaveTemplateCommand = new DelegateCommand(ExecuteChartSaveTemplate);
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index 4bfb69c7..90c33782 100755
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index a0c1e514..373cf2ae 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -5944,6 +5944,12 @@ string OnRequest(string json)
case 8: //SymbolInfoString
response = ExecuteRequest_SymbolInfoString(jo);
break;
+ case 9: //ChartTimePriceToXY
+ response = ExecuteRequest_ChartTimePriceToXY(jo);
+ break;
+ case 10: //ChartXYToTimePrice
+ response = ExecuteRequest_ChartXYToTimePrice(jo);
+ break;
default:
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
response = CreateErrorResponse(-1, "Unknown request type");
@@ -6357,6 +6363,73 @@ string ExecuteRequest_SymbolInfoString(JSONObject *jo)
return CreateSuccessResponse("Value", result_value_jo);
}
+
+string ExecuteRequest_ChartTimePriceToXY(JSONObject *jo)
+{
+ CHECK_JSON_VALUE(jo, "ChartId", CreateErrorResponse(-1, "Undefinded mandatory parameter ChartId"));
+ long chart_id = jo.getLong("ChartId");
+
+ CHECK_JSON_VALUE(jo, "SubWindow", CreateErrorResponse(-1, "Undefinded mandatory parameter SubWindow"));
+ int sub_window = jo.getInt("SubWindow");
+
+ CHECK_JSON_VALUE(jo, "MtTime", CreateErrorResponse(-1, "Undefinded mandatory parameter MtTime"));
+ datetime time = (datetime)jo.getInt("MtTime");
+
+ CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
+ double price = jo.getDouble("Price");
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: chart_id = %d, sub_window = %d, time = %s", __FUNCTION__, chart_id, sub_window, TimeToString(time));
+#endif
+
+ int x,y;
+ bool ok = ChartTimePriceToXY(chart_id, sub_window, time, price, x, y);
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: ok = %s, x = %d, y = %d", __FUNCTION__, BoolToString(ok), x, y);
+#endif
+
+ JSONObject* result_value_jo = new JSONObject();
+ result_value_jo.put("RetVal", new JSONBool(ok));
+ result_value_jo.put("X", new JSONNumber(x));
+ result_value_jo.put("Y", new JSONNumber(y));
+
+ return CreateSuccessResponse("Value", result_value_jo);
+}
+
+string ExecuteRequest_ChartXYToTimePrice(JSONObject *jo)
+{
+ CHECK_JSON_VALUE(jo, "ChartId", CreateErrorResponse(-1, "Undefinded mandatory parameter ChartId"));
+ long chart_id = jo.getLong("ChartId");
+
+ CHECK_JSON_VALUE(jo, "X", CreateErrorResponse(-1, "Undefinded mandatory parameter X"));
+ int x = jo.getInt("X");
+
+ CHECK_JSON_VALUE(jo, "Y", CreateErrorResponse(-1, "Undefinded mandatory parameter Y"));
+ int y = jo.getInt("Y");
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: chart_id = %d, x = %d, y = %d", __FUNCTION__, chart_id, x, y);
+#endif
+
+ int sub_window;
+ datetime time;
+ double price;
+ bool ok = ChartXYToTimePrice(chart_id, x, y, sub_window, time, price);
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: ok = %s, sub_window = %d, time = %s, price = %f", __FUNCTION__, BoolToString(ok), sub_window, TimeToString(time), price);
+#endif
+
+ JSONObject* result_value_jo = new JSONObject();
+ result_value_jo.put("RetVal", new JSONBool(ok));
+ result_value_jo.put("SubWindow", new JSONNumber(sub_window));
+ result_value_jo.put("MtTime", new JSONNumber((int)time));
+ result_value_jo.put("Price", new JSONNumber(price));
+
+ return CreateSuccessResponse("Value", result_value_jo);
+}
+
//------------ Events -------------------------------------------------------
enum MtEventTypes