Issue #92: Updated test application (MT5) to use functions IndicatorCreate and IndicatorRelease

This commit is contained in:
vdemydiuk
2018-02-27 18:26:37 +02:00
parent f7e06c1570
commit 0086b02bc8
6 changed files with 108 additions and 59 deletions
+55 -25
View File
@@ -84,6 +84,13 @@
<x:Type TypeName="mtapi5:ENUM_TIMEFRAMES"/> <x:Type TypeName="mtapi5:ENUM_TIMEFRAMES"/>
</ObjectDataProvider.MethodParameters> </ObjectDataProvider.MethodParameters>
</ObjectDataProvider> </ObjectDataProvider>
<ObjectDataProvider x:Key="ENUM_INDICATOR_Key" MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="mtapi5:ENUM_INDICATOR"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources> </Window.Resources>
<Grid x:Name="_MainLayout"> <Grid x:Name="_MainLayout">
@@ -305,32 +312,37 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid Grid.Column="1"> <Grid Grid.Column="1" Margin="2">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid Grid.Row="0">
<ColumnDefinition Width="Auto"/> <Grid.RowDefinitions>
<ColumnDefinition Width="*"/> <RowDefinition Height="Auto"/>
</Grid.ColumnDefinitions> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Symbol Name" Margin="1"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="TimeFrame" Margin="1" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="StartPos" Margin="1" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Count" Margin="1" HorizontalAlignment="Right"/>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}" Margin="1"/>
<ComboBox Grid.Row="1" Grid.Column="1" Margin="1"
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}" Margin="1"/>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}" Margin="1"/>
</Grid>
<TextBox Grid.Row="0" Text="symbolName"/> <WrapPanel Grid.Row="1" Grid.Column="0" Margin="5">
<TextBox Grid.Row="1" Grid.Column="0" Text="timeframe"/>
<TextBox Grid.Row="2" Grid.Column="0" Text="startPos"/>
<TextBox Grid.Row="3" Grid.Column="0" Text="count"/>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}"/>
<ComboBox Grid.Row="1" Grid.Column="1"
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}"/>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}"/>
<WrapPanel Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="10">
<Button Command="{Binding CopyRatesCommand}" Margin="1" <Button Command="{Binding CopyRatesCommand}" Margin="1"
Content="CopyRates" HorizontalAlignment="Left" /> Content="CopyRates" HorizontalAlignment="Left" />
<Button Command="{Binding CopyTimesCommand}" Margin="1" <Button Command="{Binding CopyTimesCommand}" Margin="1"
@@ -351,15 +363,33 @@
Content="CopySpread" HorizontalAlignment="Left" /> Content="CopySpread" HorizontalAlignment="Left" />
<Button Command="{Binding CopyTicksCommand}" Margin="1" <Button Command="{Binding CopyTicksCommand}" Margin="1"
Content="CopyTicks" HorizontalAlignment="Left" /> Content="CopyTicks" HorizontalAlignment="Left" />
<Button Command="{Binding IndicatorCreateCommand}" Margin="1"
Content="IndicatorCreate" HorizontalAlignment="Left" />
<Button Command="{Binding IndicatorReleaseCommand}" Margin="1"
Content="IndicatorRelease" HorizontalAlignment="Left" />
</WrapPanel> </WrapPanel>
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ComboBox Grid.Row="0" Grid.Column="0"
ItemsSource="{Binding Source={StaticResource ENUM_INDICATOR_Key}}"
SelectedItem="{Binding TimeSeriesValues.IndicatorType}"/>
<Button Grid.Row="0" Grid.Column="1" Command="{Binding IndicatorCreateCommand}" Margin="2"
Content="IndicatorCreate" HorizontalAlignment="Left" />
<Label Grid.Row="1" Grid.Column="0" Content="Indicator handle:" Margin="2"/>
<TextBox Grid.Row="1" Grid.Column="0" Margin="2" Width="30" PreviewTextInput="NumberValidationTextBox" Text="{Binding TimeSeriesValues.IndicatorHandle}"></TextBox>
<Button Grid.Row="1" Grid.Column="1" Command="{Binding IndicatorReleaseCommand}" Margin="2"
Content="IndicatorRelease" HorizontalAlignment="Left" />
</Grid>
</Grid> </Grid>
<ListBox ItemsSource="{Binding TimeSeriesResults}" /> <ListBox Grid.Column="0" ItemsSource="{Binding TimeSeriesResults}" />
</Grid> </Grid>
</TabItem> </TabItem>
+12 -17
View File
@@ -1,37 +1,32 @@
using System; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MtApi5TestClient namespace MtApi5TestClient
{ {
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow
{ {
ViewModel _vm { get; set; } private ViewModel Vm { get; }
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
_vm = new ViewModel(); Vm = new ViewModel();
_MainLayout.DataContext = _vm; _MainLayout.DataContext = Vm;
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ {
_vm.Close(); Vm.Close();
}
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
} }
} }
} }
@@ -1,21 +1,17 @@
using System; using MtApi5;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MtApi5;
using System.ComponentModel; using System.ComponentModel;
namespace MtApi5TestClient namespace MtApi5TestClient
{ {
public class TimeSeriesValueViewModel : INotifyPropertyChanged public class TimeSeriesValueViewModel : INotifyPropertyChanged
{ {
private string _SymbolValue; private string _symbolValue;
public string SymbolValue public string SymbolValue
{ {
get { return _SymbolValue; } get { return _symbolValue; }
set set
{ {
_SymbolValue = value; _symbolValue = value;
OnPropertyChanged("SymbolValue"); OnPropertyChanged("SymbolValue");
} }
} }
@@ -24,13 +20,36 @@ namespace MtApi5TestClient
public int StartPos { get; set; } public int StartPos { get; set; }
public int Count { get; set; } public int Count { get; set; }
private int _indicatorHandle;
public int IndicatorHandle
{
get { return _indicatorHandle; }
set
{
_indicatorHandle = value;
OnPropertyChanged("IndicatorHandle");
}
}
private ENUM_INDICATOR _indicatorType = ENUM_INDICATOR.IND_MACD;
public ENUM_INDICATOR IndicatorType
{
get { return _indicatorType; }
set
{
_indicatorType = value;
OnPropertyChanged("IndicatorType");
}
}
#region INotifyPropertyChanged #region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) protected virtual void OnPropertyChanged(string propertyName)
{ {
PropertyChangedEventHandler handler = PropertyChanged; var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
#endregion #endregion
} }
+11 -6
View File
@@ -7,7 +7,6 @@ using MtApi5;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Documents;
namespace MtApi5TestClient namespace MtApi5TestClient
{ {
@@ -568,12 +567,17 @@ namespace MtApi5TestClient
new MqlParam new MqlParam
{ {
DataType = ENUM_DATATYPE.TYPE_INT, DataType = ENUM_DATATYPE.TYPE_INT,
IntegerValue = 0 IntegerValue = 12
}, },
new MqlParam new MqlParam
{ {
DataType = ENUM_DATATYPE.TYPE_INT, DataType = ENUM_DATATYPE.TYPE_INT,
IntegerValue = 21 IntegerValue = 26
},
new MqlParam
{
DataType = ENUM_DATATYPE.TYPE_INT,
IntegerValue = 9
}, },
new MqlParam new MqlParam
{ {
@@ -584,17 +588,18 @@ namespace MtApi5TestClient
const string symbol = "EURUSD"; const string symbol = "EURUSD";
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1; const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
const ENUM_INDICATOR indicatorType = ENUM_INDICATOR.IND_MA; const ENUM_INDICATOR indicatorType = ENUM_INDICATOR.IND_MACD;
var retVal = await Execute(() => _mtApiClient.IndicatorCreate(symbol, timeframe, indicatorType, parameters)); var retVal = await Execute(() => _mtApiClient.IndicatorCreate(symbol, timeframe, indicatorType, parameters));
TimeSeriesValues.IndicatorHandle = retVal;
AddLog($"IndicatorCreate [IND_MA]: result - {retVal}"); AddLog($"IndicatorCreate [IND_MA]: result - {retVal}");
} }
private async void ExecuteIndicatorRelease(object o) private async void ExecuteIndicatorRelease(object o)
{ {
const int indicatorHandle = 111; var indicatorHandle = TimeSeriesValues.IndicatorHandle;
var retVal = await Execute(() => _mtApiClient.IndicatorRelease(indicatorHandle)); var retVal = await Execute(() => _mtApiClient.IndicatorRelease(indicatorHandle));
AddLog($"IndicatorRelease: result - {retVal}"); AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
} }
private async void ExecuteCopyRates(object o) private async void ExecuteCopyRates(object o)
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -39,7 +39,7 @@
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err); bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
#import #import
#define __DEBUG_LOG__ //#define __DEBUG_LOG__
input int Port = 8228; input int Port = 8228;