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 //Checkup
GetLastError = 132, GetLastError = 132,
TerminalInfoString = 153, //TODO TerminalInfoString = 153,
TerminalInfoInteger = 204, //TODO TerminalInfoInteger = 204,
TerminalInfoDouble = 205, //TODO TerminalInfoDouble = 205,
//Common Functions //Common Functions
Alert = 136, //TODO Alert = 136,
Comment = 137, //TODO Comment = 137, //TODO
GetTickCount = 138, //TODO GetTickCount = 138, //TODO
GetMicrosecondCount = 139, //TODO GetMicrosecondCount = 139, //TODO
+13 -2
View File
@@ -2152,16 +2152,27 @@ namespace MtApi5
#region Common Functions #region Common Functions
///<summary> ///<summary>
///It enters a message in the Expert Advisor log. ///It enters a message in the Expert Advisor log.
///</summary> ///</summary>
///<param name="message">Symbol name.</param> ///<param name="message">Message</param>
public bool Print(string message) public bool Print(string message)
{ {
var commandParameters = new ArrayList { message }; var commandParameters = new ArrayList { message };
return SendCommand<bool>(Mt5CommandType.Print, commandParameters); 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 #endregion // Common Functions
#region Object Functions #region Object Functions
+10 -6
View File
@@ -526,12 +526,16 @@
</WrapPanel> </WrapPanel>
<Grid Margin="10" Grid.Row="1"> <Grid Margin="10" Grid.Row="1">
<Grid.ColumnDefinitions> <Grid.RowDefinitions>
<ColumnDefinition Width="*"/> <RowDefinition Height="Auto"/>
<ColumnDefinition Width="Auto"/> <RowDefinition Height="Auto"/>
</Grid.ColumnDefinitions> </Grid.RowDefinitions>
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/> <TextBox Grid.Row="0" Text="{Binding MessageText}" Margin="2"/>
<Button Grid.Column="1" Command="{Binding PrintCommand}" Content="Print" Margin="5"/> <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>
</Grid> </Grid>
</TabItem> </TabItem>
+10
View File
@@ -70,6 +70,7 @@ namespace MtApi5TestClient
public DelegateCommand GetLastErrorCommand { get; private set; } public DelegateCommand GetLastErrorCommand { get; private set; }
public DelegateCommand ResetLastErrorCommand { get; private set; } public DelegateCommand ResetLastErrorCommand { get; private set; }
public DelegateCommand PrintCommand { get; private set; } public DelegateCommand PrintCommand { get; private set; }
public DelegateCommand AlertCommand { get; private set; }
public DelegateCommand iCustomCommand { get; private set; } public DelegateCommand iCustomCommand { get; private set; }
@@ -425,6 +426,7 @@ namespace MtApi5TestClient
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen); PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
PrintCommand = new DelegateCommand(ExecutePrint); PrintCommand = new DelegateCommand(ExecutePrint);
AlertCommand = new DelegateCommand(ExecuteAlert);
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError); GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError); ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
@@ -1136,6 +1138,14 @@ namespace MtApi5TestClient
AddLog($"Print: message print in MetaTrader - {retVal}"); 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) private async void ExecuteGetLastError(object obj)
{ {
var retVal = await Execute(() => _mtApiClient.GetLastError()); 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 case 132: //GetLastError
Execute_GetLastError(); Execute_GetLastError();
break; break;
case 136: //Alert
Execute_Alert();
break;
case 143: //ResetLastError case 143: //ResetLastError
Execute_ResetLastError(); Execute_ResetLastError();
break; break;
@@ -759,7 +762,8 @@ int executeCommand()
return; \ 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)) \ #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() void Execute_PositionGetTicket()
{ {
int index; int index;
GET_INTEGER_VALUE(0, index, "PositionGetTicket", "index"); GET_INT_VALUE(0, index, "PositionGetTicket", "index");
#ifdef __DEBUG_LOG__ #ifdef __DEBUG_LOG__
PrintFormat("%s: index = %d", __FUNCTION__, index); PrintFormat("%s: index = %d", __FUNCTION__, index);
@@ -5533,7 +5537,7 @@ void Execute_TimeGMT()
void Execute_IndicatorRelease() void Execute_IndicatorRelease()
{ {
int indicator_handle; int indicator_handle;
GET_INTEGER_VALUE(0, indicator_handle, "IndicatorRelease", "indicator_handle"); GET_INT_VALUE(0, indicator_handle, "IndicatorRelease", "indicator_handle");
#ifdef __DEBUG_LOG__ #ifdef __DEBUG_LOG__
PrintFormat("%s: indicator_handle = %d", __FUNCTION__, indicator_handle); PrintFormat("%s: indicator_handle = %d", __FUNCTION__, indicator_handle);
@@ -5556,6 +5560,25 @@ void Execute_GetLastError()
SEND_INT_RESPONSE(last_error, "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() void Execute_ResetLastError()
{ {
ResetLastError(); ResetLastError();