Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions MtApi5/MtApi5Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,55 @@ public void Alert(string message)
SendCommand<object>(ExecutorHandle, Mt5CommandType.Alert, cmdParams);
}

///<summary>
///Outputs a comment in the left top corner of the chart.
///</summary>
///<param name="comments">Comment text.</param>
///<returns>true after the comment has been output.</returns>
public bool Comment(string comments)
{
Dictionary<string, object> cmdParams = new() { { "Comments", comments ?? string.Empty } };
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.Comment, cmdParams);
}

///<summary>
///Plays a sound file.
///</summary>
///<param name="filename">Path to a sound file relative to the terminal_directory\Sounds folder.</param>
///<returns>true if the file is found; otherwise false.</returns>
public bool PlaySound(string filename)
{
Dictionary<string, object> cmdParams = new() { { "Filename", filename ?? string.Empty } };
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.PlaySound, cmdParams);
}

///<summary>
///Sends push notifications to the mobile terminals whose MetaQuotes IDs are specified in the terminal settings.
///</summary>
///<param name="text">Notification text (up to 255 characters).</param>
///<returns>true if the notification has been sent; otherwise false.</returns>
public bool SendNotification(string text)
{
Dictionary<string, object> cmdParams = new() { { "Text", text ?? string.Empty } };
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.SendNotification, cmdParams);
}

///<summary>
///Sends an email at the address specified in the settings window of the Email tab.
///</summary>
///<param name="subject">Email header.</param>
///<param name="someText">Email body.</param>
///<returns>true if the email has been queued for sending; otherwise false.</returns>
public bool SendMail(string subject, string someText)
{
Dictionary<string, object> cmdParams = new()
{
{ "Subject", subject ?? string.Empty },
{ "SomeText", someText ?? string.Empty }
};
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.SendMail, cmdParams);
}

///<summary>
///Gives program operation completion command when testing.
///</summary>
Expand Down
8 changes: 4 additions & 4 deletions MtApi5/MtProtocol/Mt5CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ internal enum Mt5CommandType

//Common Functions
Alert = 136,
Comment = 137, //TODO
Comment = 137,
GetTickCount = 138, //TODO
GetMicrosecondCount = 139, //TODO
MessageBox = 140, //TODO
PeriodSeconds = 141, //TODO
PlaySound = 142, //TODO
PlaySound = 142,
Print = 68,
ResetLastError = 143,
SendNotification = 144, //TODO
SendMail = 145, //TODO
SendNotification = 144,
SendMail = 145,

//Global Variables
GlobalVariableCheck = 146,
Expand Down
2 changes: 2 additions & 0 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Command="{Binding PrintCommand}" Content="Print" Margin="2" />
<Button Command="{Binding AlertCommand}" Content="Alert" Margin="2" />
<Button Command="{Binding CommentCommand}" Content="Comment" Margin="2" />
<Button Command="{Binding SendNotificationCommand}" Content="SendNotification" Margin="2" />
</StackPanel>

</Grid>
Expand Down
20 changes: 20 additions & 0 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand ResetLastErrorCommand { get; private set; }
public DelegateCommand PrintCommand { get; private set; }
public DelegateCommand AlertCommand { get; private set; }
public DelegateCommand CommentCommand { get; private set; }
public DelegateCommand SendNotificationCommand { get; private set; }
public DelegateCommand TesterStopCommand { get; private set; }

public DelegateCommand TimeCurrentCommand { get; private set; }
Expand Down Expand Up @@ -453,6 +455,8 @@ private void InitCommands()

PrintCommand = new DelegateCommand(ExecutePrint);
AlertCommand = new DelegateCommand(ExecuteAlert);
CommentCommand = new DelegateCommand(ExecuteComment);
SendNotificationCommand = new DelegateCommand(ExecuteSendNotification);
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);
Expand Down Expand Up @@ -1318,6 +1322,22 @@ private void ExecuteAlert(object obj)
AddLog($"Alert: send alert to MetaTrader - {message}.");
}

private async void ExecuteComment(object obj)
{
var message = MessageText;

var retVal = await Execute(() => _mtApiClient.Comment(message));
AddLog($"Comment: message shown on MetaTrader chart - {retVal}");
}

private async void ExecuteSendNotification(object obj)
{
var message = MessageText;

var retVal = await Execute(() => _mtApiClient.SendNotification(message));
AddLog($"SendNotification: notification sent - {retVal}");
}

private async void ExecuteGetLastError(object obj)
{
var retVal = await Execute(() => _mtApiClient.GetLastError());
Expand Down
Binary file modified mq5/MtApi5.ex5
Binary file not shown.
41 changes: 41 additions & 0 deletions mq5/MtApi5.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ int preinit()
ADD_EXECUTOR(130, TimeGMT);
ADD_EXECUTOR(132, GetLastError);
ADD_EXECUTOR(136, Alert);
ADD_EXECUTOR(137, Comment);
ADD_EXECUTOR(142, PlaySound);
ADD_EXECUTOR(143, ResetLastError);
ADD_EXECUTOR(144, SendNotification);
ADD_EXECUTOR(145, SendMail);
ADD_EXECUTOR(146, GlobalVariableCheck);
ADD_EXECUTOR(147, GlobalVariableTime);
ADD_EXECUTOR(148, GlobalVariableDel);
Expand Down Expand Up @@ -2545,6 +2549,43 @@ string Execute_Alert()
return CreateSuccessResponse();
}

string Execute_Comment()
{
GET_JSON_PAYLOAD(jo);
GET_STRING_JSON_VALUE(jo, "Comments", comments);

Comment(comments);
return CreateSuccessResponse(new JSONBool(true));
}

string Execute_PlaySound()
{
GET_JSON_PAYLOAD(jo);
GET_STRING_JSON_VALUE(jo, "Filename", filename);

bool result = PlaySound(filename);
return CreateSuccessResponse(new JSONBool(result));
}

string Execute_SendNotification()
{
GET_JSON_PAYLOAD(jo);
GET_STRING_JSON_VALUE(jo, "Text", text);

bool result = SendNotification(text);
return CreateSuccessResponse(new JSONBool(result));
}

string Execute_SendMail()
{
GET_JSON_PAYLOAD(jo);
GET_STRING_JSON_VALUE(jo, "Subject", subject);
GET_STRING_JSON_VALUE(jo, "SomeText", some_text);

bool result = SendMail(subject, some_text);
return CreateSuccessResponse(new JSONBool(result));
}

string Execute_ResetLastError()
{
ResetLastError();
Expand Down