SendNotification
SendNotification
发送推送通知到在“通知”标签指定MetaQuotes ID的移动程序端。
bool SendNotification(
string text // 通知文本
);参数
- text
[in] 通知文本。信息长度不应该超过 255 字符。
返回值
如果通知从程序端成功发送,则返回true;如果失败则返回false。推送通知失败后检查时,GetLastError () 可能返回其中以下一种错误:
- 4515 ERR_NOTIFICATION_SEND_FAILED,
- 4516 ERR_NOTIFICATION_WRONG_PARAMETER,
- 4517 ERR_NOTIFICATION_WRONG_SETTINGS,
- 4518 ERR_NOTIFICATION_TOO_FREQUENT.
注意
为SendNotification()函数设置了严格的使用限制:每秒钟调用不能超过2次,每分钟调用不能超过10次。动态监控使用频率。如果违反限制,函数将被禁用。
SendNotification() 函数在策略测试中不工作。
示例:
//+------------------------------------------------------------------+
//| SendNotification.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com
#property version "1.00"
#define MESSAGE "Test Message"
//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart(void)
{
//--- 检查从终端中发送通知的许可
if(!TerminalInfoInteger(TERMINAL_NOTIFICATIONS_ENABLED))
{
Print("Error. The client terminal does not have permission to send notifications");
return;
}
//--- 发送通知
ResetLastError();
if(!SendNotification(MESSAGE))
Print("SendNotification() failed. Error ",GetLastError());
}