虾推啥可以用中文在MT5 MetaTrader上推送消息,非常的简单. 其实就是一行代码.
为了做演示, 我会列出详细步骤如何在MT4中推送中文信息到微信,只要你有虾推啥的Token就可以一行代码搞定.
步骤
- 获取虾推啥的Token. 免费的,关注公众号”虾推啥”自动获取.
- 下载按照MetaTrader 5. 你可以用Baidu搜索这个软件,下载安装即可. 下载链接我就不放了,很容易搜到.安装好了以后,桌面有个下面这个图标.
- 双击这个图标,就是打开软件MetaTrader5, 把虾推啥的网站加入到这个软件可以信任访问的列表里, 这里MetaTrader为了安全,不允许代码访问外部网络,所以要添加我们虾推啥的网址到这里. 路径: 工具->选项->勾选允许WebRequest用于所列的URL. 然后填写虾推啥的网址. 这里我为了方便演示,把发送的消息也放在这里.你们将来使用只要输入前面的网址http://wx.xtuis.cn/你的虾推啥Token.send,然后用Parameter填写内容调用就可以了.
我填写的网址: http://wx.xtuis.cn/你的虾推啥Token.send?text=MT5消息&desp=欧元破位啦
- 点击下图的IDE图标 ,打开编写代码的MT5 Editor.
- 在Meta Editor上,如下图,选择新建,然后选择”脚本”, 然后给个脚本名字,我这里是xtuis_push. 点击完成. 这样就生成了一个空白的脚本.
- 关键代码就两行.
为了让大家简单,贴入下面的代码,注意修改为里自己的虾推啥Token. 然后点击运行按钮.
//+------------------------------------------------------------------+
//| xtuis_push.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"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
string Server[]; // array of server names
double Long[], Short[]; // array for swap information
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
//---
string cookie=NULL,headers,responses;
char post[],result[];
string url="http://wx.xtuis.cn/XXXXXXXXXX.send?text=MT5消息&desp=欧元破位啦";
string newheader="Accept:application/json, text/javascript,charset=utf-8, */*; q=0.0\r\nContent-Type:application/x-www-form-urlencoded";;
//--- To enable access to the server, you should add URL "https://finance.yahoo.com"
//--- to the list of allowed URLs (Main Menu->Tools->Options, tab "Expert Advisors"):
//--- Resetting the last error code
ResetLastError();
//--- Downloading a html page from Yahoo Finance
int res=WebRequest("GET",url,newheader,newheader,500,post,0,result,newheader);
if(res==-1)
{
Print("Error in WebRequest. Error code =",GetLastError());
//--- Perhaps the URL is not listed, display a message about the necessity to add the address
MessageBox("Add the address '"+url+"' to the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
}
else
{
if(res==200)
{
//--- Successful download
PrintFormat("The file has been successfully downloaded, File size %d byte.",ArraySize(result));
//PrintFormat("Server headers: %s",headers);
//--- Saving the data to a file
int filehandle=FileOpen("url.htm",FILE_WRITE|FILE_BIN);
if(filehandle!=INVALID_HANDLE)
{
//--- Saving the contents of the result[] array to a file
FileWriteArray(filehandle,result,0,ArraySize(result));
//--- Closing the file
FileClose(filehandle);
}
else
Print("Error in FileOpen. Error code =",GetLastError());
}
else
PrintFormat("Downloading '%s' failed, error code %d",url,res);
}
}
//+------------------------------------------------------------------+
然后你的虾推啥就会收到消息啦
好啦. 希望你能喜欢.