Issue #21: Added function Print to MtApi (MT5)

This commit is contained in:
vdemydiuk
2016-10-21 17:52:54 +03:00
parent 094cdcc448
commit 05452e3b90
6 changed files with 78 additions and 12 deletions
+3 -1
View File
@@ -108,6 +108,8 @@ namespace MtApi5
//Backtesting //Backtesting
BacktestingReady = 66, BacktestingReady = 66,
IsTesting = 67 IsTesting = 67,
Print = 68
} }
} }
+13
View File
@@ -1392,6 +1392,19 @@ namespace MtApi5
#endregion #endregion
#region Common Functions
///<summary>
///It enters a message in the Expert Advisor log.
///</summary>
///<param name="message">Symbol name.</param>
public bool Print(string message)
{
var commandParameters = new ArrayList { message };
return SendCommand<bool>(Mt5CommandType.Print, commandParameters);
}
#endregion
#endregion #endregion
#region Properties #region Properties
+27 -11
View File
@@ -263,36 +263,52 @@
</TabItem> </TabItem>
<TabItem Header="Account Information"> <TabItem Header="Account Information">
<Grid> <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.4*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.4*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ComboBox Grid.Column="0" Grid.Row="0" <ComboBox Grid.Column="0" Grid.Row="0"
SelectedItem="{Binding AccountInfoDoublePropertyId}" SelectedItem="{Binding AccountInfoDoublePropertyId}"
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_DOUBLE_Key}}"/> ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_DOUBLE_Key}}"/>
<Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0" <Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0"
Command="{Binding AccountInfoDoubleCommand}" Command="{Binding AccountInfoDoubleCommand}"
Content="AccountInfoDouble" HorizontalAlignment="Left" /> Content="AccountInfoDouble" HorizontalAlignment="Left" />
<ComboBox Grid.Column="0" Grid.Row="1" <ComboBox Grid.Column="0" Grid.Row="1"
SelectedItem="{Binding AccountInfoIntegerPropertyId}" SelectedItem="{Binding AccountInfoIntegerPropertyId}"
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_INTEGER_Key}}"/> ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_INTEGER_Key}}"/>
<Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" <Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"
Command="{Binding AccountInfoIntegerCommand}" Command="{Binding AccountInfoIntegerCommand}"
Content="AccountInfoInteger" HorizontalAlignment="Left" /> Content="AccountInfoInteger" HorizontalAlignment="Left" />
<ComboBox Grid.Column="0" Grid.Row="2" <ComboBox Grid.Column="0" Grid.Row="2"
SelectedItem="{Binding AccountInfoStringPropertyId}" SelectedItem="{Binding AccountInfoStringPropertyId}"
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_STRING_Key}}"/> ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_STRING_Key}}"/>
<Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0" <Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"
Command="{Binding AccountInfoStringCommand}" Command="{Binding AccountInfoStringCommand}"
Content="AccountInfoString" HorizontalAlignment="Left" /> Content="AccountInfoString" HorizontalAlignment="Left" />
</Grid>
<Grid Margin="10" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/>
<Button Grid.Column="1" Content="Print" Command="{Binding PrintCommand}" Margin="5"/>
</Grid>
</Grid> </Grid>
</TabItem> </TabItem>
+23
View File
@@ -47,6 +47,8 @@ namespace MtApi5TestClient
public DelegateCommand MarketBookGetCommand { get; private set; } public DelegateCommand MarketBookGetCommand { get; private set; }
public DelegateCommand PositionOpenCommand { get; private set; } public DelegateCommand PositionOpenCommand { get; private set; }
public DelegateCommand PrintCommand { get; private set; }
#endregion #endregion
#region Properties #region Properties
@@ -131,6 +133,17 @@ namespace MtApi5TestClient
public ObservableCollection<string> TimeSeriesResults { get; } = new ObservableCollection<string>(); public ObservableCollection<string> TimeSeriesResults { get; } = new ObservableCollection<string>();
private string _messageText = "Print some text in MetaTrader expert console";
public string MessageText
{
get { return _messageText; }
set
{
_messageText = value;
OnPropertyChanged("MessageText");
}
}
#endregion #endregion
#region Public Methods #region Public Methods
@@ -210,6 +223,8 @@ namespace MtApi5TestClient
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet); MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen); PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
PrintCommand = new DelegateCommand(ExecutePrint);
} }
private bool CanExecuteConnect(object o) private bool CanExecuteConnect(object o)
@@ -711,6 +726,14 @@ namespace MtApi5TestClient
AddLog($"PositionOpen: symbol EURUSD result = {retVal}"); AddLog($"PositionOpen: symbol EURUSD result = {retVal}");
} }
private async void ExecutePrint(object obj)
{
var message = MessageText;
var retVal = await Execute(() => _mtApiClient.Print(message));
AddLog($"Print: message print in MetaTrader - {retVal}");
}
private static void RunOnUiThread(Action action) private static void RunOnUiThread(Action action)
{ {
Application.Current?.Dispatcher.Invoke(action); Application.Current?.Dispatcher.Invoke(action);
BIN
View File
Binary file not shown.
+12
View File
@@ -1692,6 +1692,18 @@ int executeCommand()
sendBooleanResponse(ExpertHandle, IsTesting()); sendBooleanResponse(ExpertHandle, IsTesting());
} }
break; break;
case 68: //Print
{
string printMsg;
StringInit(printMsg, 1000, 0);
getStringValue(ExpertHandle, 0, printMsg);
Print(printMsg);
sendBooleanResponse(ExpertHandle, true);
}
break;
default: default:
Print("Unknown command type = ", commandType); Print("Unknown command type = ", commandType);