Skip to content

Commit 05452e3

Browse files
committed
Issue #21: Added function Print to MtApi (MT5)
1 parent 094cdcc commit 05452e3

File tree

6 files changed

+78
-12
lines changed

6 files changed

+78
-12
lines changed

MtApi5/Mt5CommandType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ internal enum Mt5CommandType
108108

109109
//Backtesting
110110
BacktestingReady = 66,
111-
IsTesting = 67
111+
IsTesting = 67,
112+
113+
Print = 68
112114
}
113115
}

MtApi5/MtApi5Client.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,19 @@ public bool MarketBookGet(string symbol, out MqlBookInfo[] book)
13921392

13931393
#endregion
13941394

1395+
#region Common Functions
1396+
///<summary>
1397+
///It enters a message in the Expert Advisor log.
1398+
///</summary>
1399+
///<param name="message">Symbol name.</param>
1400+
public bool Print(string message)
1401+
{
1402+
var commandParameters = new ArrayList { message };
1403+
1404+
return SendCommand<bool>(Mt5CommandType.Print, commandParameters);
1405+
}
1406+
#endregion
1407+
13951408
#endregion
13961409

13971410
#region Properties

TestClients/MtApi5TestClient/MainWindow.xaml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,36 +263,52 @@
263263
</TabItem>
264264
<TabItem Header="Account Information">
265265
<Grid>
266-
<Grid.ColumnDefinitions>
267-
<ColumnDefinition Width="0.4*"/>
268-
<ColumnDefinition Width="*"/>
269-
</Grid.ColumnDefinitions>
270266
<Grid.RowDefinitions>
271267
<RowDefinition Height="Auto"/>
272268
<RowDefinition Height="Auto"/>
273-
<RowDefinition Height="Auto"/>
274269
</Grid.RowDefinitions>
270+
<Grid Grid.Row="0" Margin="10">
271+
<Grid.ColumnDefinitions>
272+
<ColumnDefinition Width="0.4*"/>
273+
<ColumnDefinition Width="*"/>
274+
</Grid.ColumnDefinitions>
275+
<Grid.RowDefinitions>
276+
<RowDefinition Height="Auto"/>
277+
<RowDefinition Height="Auto"/>
278+
<RowDefinition Height="Auto"/>
279+
<RowDefinition Height="Auto"/>
280+
</Grid.RowDefinitions>
275281

276-
<ComboBox Grid.Column="0" Grid.Row="0"
282+
<ComboBox Grid.Column="0" Grid.Row="0"
277283
SelectedItem="{Binding AccountInfoDoublePropertyId}"
278284
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_DOUBLE_Key}}"/>
279-
<Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0"
285+
<Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0"
280286
Command="{Binding AccountInfoDoubleCommand}"
281287
Content="AccountInfoDouble" HorizontalAlignment="Left" />
282288

283-
<ComboBox Grid.Column="0" Grid.Row="1"
289+
<ComboBox Grid.Column="0" Grid.Row="1"
284290
SelectedItem="{Binding AccountInfoIntegerPropertyId}"
285291
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_INTEGER_Key}}"/>
286-
<Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"
292+
<Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"
287293
Command="{Binding AccountInfoIntegerCommand}"
288294
Content="AccountInfoInteger" HorizontalAlignment="Left" />
289295

290-
<ComboBox Grid.Column="0" Grid.Row="2"
296+
<ComboBox Grid.Column="0" Grid.Row="2"
291297
SelectedItem="{Binding AccountInfoStringPropertyId}"
292298
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_STRING_Key}}"/>
293-
<Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"
299+
<Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"
294300
Command="{Binding AccountInfoStringCommand}"
295301
Content="AccountInfoString" HorizontalAlignment="Left" />
302+
</Grid>
303+
<Grid Margin="10" Grid.Row="1">
304+
<Grid.ColumnDefinitions>
305+
<ColumnDefinition Width="*"/>
306+
<ColumnDefinition Width="Auto"/>
307+
</Grid.ColumnDefinitions>
308+
309+
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/>
310+
<Button Grid.Column="1" Content="Print" Command="{Binding PrintCommand}" Margin="5"/>
311+
</Grid>
296312
</Grid>
297313
</TabItem>
298314

TestClients/MtApi5TestClient/ViewModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ViewModel : INotifyPropertyChanged
4747
public DelegateCommand MarketBookGetCommand { get; private set; }
4848

4949
public DelegateCommand PositionOpenCommand { get; private set; }
50+
51+
public DelegateCommand PrintCommand { get; private set; }
5052
#endregion
5153

5254
#region Properties
@@ -131,6 +133,17 @@ public MqlTradeRequestViewModel TradeRequest
131133

132134
public ObservableCollection<string> TimeSeriesResults { get; } = new ObservableCollection<string>();
133135

136+
private string _messageText = "Print some text in MetaTrader expert console";
137+
public string MessageText
138+
{
139+
get { return _messageText; }
140+
set
141+
{
142+
_messageText = value;
143+
OnPropertyChanged("MessageText");
144+
}
145+
}
146+
134147
#endregion
135148

136149
#region Public Methods
@@ -210,6 +223,8 @@ private void InitCommands()
210223
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);
211224

212225
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
226+
227+
PrintCommand = new DelegateCommand(ExecutePrint);
213228
}
214229

215230
private bool CanExecuteConnect(object o)
@@ -711,6 +726,14 @@ private async void ExecutePositionOpen(object obj)
711726
AddLog($"PositionOpen: symbol EURUSD result = {retVal}");
712727
}
713728

729+
private async void ExecutePrint(object obj)
730+
{
731+
var message = MessageText;
732+
733+
var retVal = await Execute(() => _mtApiClient.Print(message));
734+
AddLog($"Print: message print in MetaTrader - {retVal}");
735+
}
736+
714737
private static void RunOnUiThread(Action action)
715738
{
716739
Application.Current?.Dispatcher.Invoke(action);

mq5/MtApi5.ex5

1.46 KB
Binary file not shown.

mq5/MtApi5.mq5

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,18 @@ int executeCommand()
16921692
sendBooleanResponse(ExpertHandle, IsTesting());
16931693
}
16941694
break;
1695+
1696+
case 68: //Print
1697+
{
1698+
string printMsg;
1699+
StringInit(printMsg, 1000, 0);
1700+
1701+
getStringValue(ExpertHandle, 0, printMsg);
1702+
1703+
Print(printMsg);
1704+
sendBooleanResponse(ExpertHandle, true);
1705+
}
1706+
break;
16951707

16961708
default:
16971709
Print("Unknown command type = ", commandType);

0 commit comments

Comments
 (0)