Implemented functions ChartTimePriceToXY, ChartXYToTimePrice (MT5)

This commit is contained in:
vdemydiuk
2018-03-13 17:28:21 +02:00
parent f3a3a582fd
commit 16f454ca61
12 changed files with 238 additions and 47 deletions
+23 -6
View File
@@ -480,12 +480,29 @@
</WrapPanel>
</TabItem>
<TabItem Header="Chart Functions">
<WrapPanel VerticalAlignment="Top" Margin="5">
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}" Margin="1"/>
<Button Command="{Binding ChartOpenCommand}" Content="ChartOpen"/>
<Button Command="{Binding ChartApplyTemplateCommand}" Content="ChartApplyTemplate"/>
<Button Command="{Binding ChartSaveTemplateCommand}" Content="ChartSaveTemplate"/>
</WrapPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5">
<TextBlock Text="Symbol" VerticalAlignment="Center" Margin="2"/>
<TextBox Width="100" Text="{Binding ChartFunctionsSymbolValue}" Margin="2"/>
</StackPanel>
<WrapPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
<Button Command="{Binding ChartOpenCommand}" Content="ChartOpen" Margin="2"/>
<Button Command="{Binding ChartTimePriceToXYCommand}" Content="ChartTimePriceToXY" Margin="2"/>
<Button Command="{Binding ChartXYToTimePriceCommand}" Content="ChartXYToTimePrice" Margin="2"/>
</WrapPanel>
<WrapPanel Grid.Row="2" VerticalAlignment="Top" Margin="5">
<Button Command="{Binding ChartApplyTemplateCommand}" Content="ChartApplyTemplate" Margin="2"/>
<Button Command="{Binding ChartSaveTemplateCommand}" Content="ChartSaveTemplate" Margin="2"/>
</WrapPanel>
</Grid>
</TabItem>
<TabItem Header="Time and Date">
<WrapPanel VerticalAlignment="Top" Margin="5">
+61 -4
View File
@@ -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);