Skip to content

Commit

Permalink
Issue #21: Added function Print to MtApi (MT5)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdemydiuk committed Oct 21, 2016
1 parent 094cdcc commit 05452e3
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 12 deletions.
4 changes: 3 additions & 1 deletion MtApi5/Mt5CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ internal enum Mt5CommandType

//Backtesting
BacktestingReady = 66,
IsTesting = 67
IsTesting = 67,

Print = 68
}
}
13 changes: 13 additions & 0 deletions MtApi5/MtApi5Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,19 @@ public bool MarketBookGet(string symbol, out MqlBookInfo[] book)

#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

#region Properties
Expand Down
38 changes: 27 additions & 11 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,36 +263,52 @@
</TabItem>
<TabItem Header="Account Information">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.4*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</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}"
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}"
Content="AccountInfoDouble" HorizontalAlignment="Left" />

<ComboBox Grid.Column="0" Grid.Row="1"
<ComboBox Grid.Column="0" Grid.Row="1"
SelectedItem="{Binding AccountInfoIntegerPropertyId}"
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}"
Content="AccountInfoInteger" HorizontalAlignment="Left" />

<ComboBox Grid.Column="0" Grid.Row="2"
<ComboBox Grid.Column="0" Grid.Row="2"
SelectedItem="{Binding AccountInfoStringPropertyId}"
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}"
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>
</TabItem>

Expand Down
23 changes: 23 additions & 0 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand MarketBookGetCommand { get; private set; }

public DelegateCommand PositionOpenCommand { get; private set; }

public DelegateCommand PrintCommand { get; private set; }
#endregion

#region Properties
Expand Down Expand Up @@ -131,6 +133,17 @@ public MqlTradeRequestViewModel TradeRequest

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

#region Public Methods
Expand Down Expand Up @@ -210,6 +223,8 @@ private void InitCommands()
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);

PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);

PrintCommand = new DelegateCommand(ExecutePrint);
}

private bool CanExecuteConnect(object o)
Expand Down Expand Up @@ -711,6 +726,14 @@ private async void ExecutePositionOpen(object obj)
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)
{
Application.Current?.Dispatcher.Invoke(action);
Expand Down
Binary file modified mq5/MtApi5.ex5
Binary file not shown.
12 changes: 12 additions & 0 deletions mq5/MtApi5.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,18 @@ int executeCommand()
sendBooleanResponse(ExpertHandle, IsTesting());
}
break;

case 68: //Print
{
string printMsg;
StringInit(printMsg, 1000, 0);

getStringValue(ExpertHandle, 0, printMsg);

Print(printMsg);
sendBooleanResponse(ExpertHandle, true);
}
break;

default:
Print("Unknown command type = ", commandType);
Expand Down

0 comments on commit 05452e3

Please sign in to comment.