Implemented function Alert (MT5)

This commit is contained in:
vdemydiuk
2018-03-13 18:24:40 +02:00
parent 16f454ca61
commit 9afd30e463
6 changed files with 63 additions and 15 deletions
+4 -4
View File
@@ -238,12 +238,12 @@ namespace MtApi5
//Checkup
GetLastError = 132,
TerminalInfoString = 153, //TODO
TerminalInfoInteger = 204, //TODO
TerminalInfoDouble = 205, //TODO
TerminalInfoString = 153,
TerminalInfoInteger = 204,
TerminalInfoDouble = 205,
//Common Functions
Alert = 136, //TODO
Alert = 136,
Comment = 137, //TODO
GetTickCount = 138, //TODO
GetMicrosecondCount = 139, //TODO
+13 -2
View File
@@ -2152,16 +2152,27 @@ namespace MtApi5
#region Common Functions
///<summary>
///It enters a message in the Expert Advisor log.
///</summary>
///<param name="message">Symbol name.</param>
///<param name="message">Message</param>
public bool Print(string message)
{
var commandParameters = new ArrayList { message };
return SendCommand<bool>(Mt5CommandType.Print, commandParameters);
}
///<summary>
///Displays a message in a separate window.
///</summary>
///<param name="message">Message</param>
public void Alert(string message)
{
var commandParameters = new ArrayList { message };
SendCommand<object>(Mt5CommandType.Alert, commandParameters);
}
#endregion // Common Functions
#region Object Functions
+10 -6
View File
@@ -526,12 +526,16 @@
</WrapPanel>
<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" Command="{Binding PrintCommand}" Content="Print" Margin="5"/>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding MessageText}" Margin="2"/>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Command="{Binding PrintCommand}" Content="Print" Margin="2" />
<Button Command="{Binding AlertCommand}" Content="Alert" Margin="2" />
</StackPanel>
</Grid>
</Grid>
</TabItem>
+10
View File
@@ -70,6 +70,7 @@ namespace MtApi5TestClient
public DelegateCommand GetLastErrorCommand { get; private set; }
public DelegateCommand ResetLastErrorCommand { get; private set; }
public DelegateCommand PrintCommand { get; private set; }
public DelegateCommand AlertCommand { get; private set; }
public DelegateCommand iCustomCommand { get; private set; }
@@ -425,6 +426,7 @@ namespace MtApi5TestClient
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
PrintCommand = new DelegateCommand(ExecutePrint);
AlertCommand = new DelegateCommand(ExecuteAlert);
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
@@ -1136,6 +1138,14 @@ namespace MtApi5TestClient
AddLog($"Print: message print in MetaTrader - {retVal}");
}
private void ExecuteAlert(object obj)
{
var message = MessageText;
_mtApiClient.Alert(message);
AddLog($"Alert: send alert to MetaTrader - {message}.");
}
private async void ExecuteGetLastError(object obj)
{
var retVal = await Execute(() => _mtApiClient.GetLastError());
BIN
View File
Binary file not shown.
+26 -3
View File
@@ -708,6 +708,9 @@ int executeCommand()
case 132: //GetLastError
Execute_GetLastError();
break;
case 136: //Alert
Execute_Alert();
break;
case 143: //ResetLastError
Execute_ResetLastError();
break;
@@ -759,7 +762,8 @@ int executeCommand()
return; \
} \
#define GET_INTEGER_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, cmd_name, param_name)
#define GET_INT_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, cmd_name, param_name)
#define GET_STRING_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getStringValue, argument_id, argument, cmd_name, param_name)
#define SEND_RESPONSE_OR_PRINT_ERROR(send_func, response, cmd_name) if (!send_func(ExpertHandle, response, _response_error)) \
@@ -942,7 +946,7 @@ void Execute_OrderCalcProfit()
void Execute_PositionGetTicket()
{
int index;
GET_INTEGER_VALUE(0, index, "PositionGetTicket", "index");
GET_INT_VALUE(0, index, "PositionGetTicket", "index");
#ifdef __DEBUG_LOG__
PrintFormat("%s: index = %d", __FUNCTION__, index);
@@ -5533,7 +5537,7 @@ void Execute_TimeGMT()
void Execute_IndicatorRelease()
{
int indicator_handle;
GET_INTEGER_VALUE(0, indicator_handle, "IndicatorRelease", "indicator_handle");
GET_INT_VALUE(0, indicator_handle, "IndicatorRelease", "indicator_handle");
#ifdef __DEBUG_LOG__
PrintFormat("%s: indicator_handle = %d", __FUNCTION__, indicator_handle);
@@ -5556,6 +5560,25 @@ void Execute_GetLastError()
SEND_INT_RESPONSE(last_error, "GetLastError");
}
void Execute_Alert()
{
string message;
StringInit(message, 1000);
GET_STRING_VALUE(0, message, "Alert", "message");
#ifdef __DEBUG_LOG__
PrintFormat("%s: message = %s", __FUNCTION__, message);
#endif
Alert(message);
if (!sendVoidResponse(ExpertHandle, _error))
{
PrintResponseError("Alert", _response_error);
}
}
void Execute_ResetLastError()
{
ResetLastError();