实时接收数据大概分为2种方式
方式1:直接通过webrequest方式去请求,
例如
void OnStart()
{
string cookie=NULL,headers;
char post[],result[];
string url="https://finance.yahoo.com";
//--- 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,cookie,NULL,500,post,0,result,headers);
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);
}
}
当然这只是获取到了数据
还要进一步解析数据,将数据转换为tick或者k 线,进行存储
以便于大家进行使用
函数
操作
CustomSymbolCreate
在指定组以指定名称创建一个自定义交易品种
CustomSymbolDelete
删除指定名称的自定义交易品种
CustomSymbolSetInteger
为自定义交易品种设置整型属性值
CustomSymbolSetDouble
为自定义交易品种设置真实型属性值
CustomSymbolSetString
为自定义交易品种设置字符串类型属性值
CustomSymbolSetMarginRate
按照订单类型和方向,为自定义交易品种设置预付款比率
CustomSymbolSetSessionQuote
为指定交易品种和工作日设置指定报价时段的起止时间
CustomSymbolSetSessionTrade
为指定交易品种和工作日设置指定交易时段的起止时间
CustomRatesDelete
删除指定时间间隔内自定义交易品种价格历史的全部柱形图
CustomRatesReplace
以MqlRates类型数组数据完全替换指定时间间隔内自定义交易品种的价格历史
CustomRatesUpdate
将丢失的柱形图添加到自定义交易品种历史并用MqlRates类型数组数据替换现有数据
CustomTicksAdd
添加MqlTick类型的数组数据到自定义交易品种的价格历史。自定义交易品种一定要在市场报价窗口来选择
CustomTicksDelete
删除指定时间间隔内自定义交易品种价格历史的全部报价
CustomTicksReplace
以MqlTick类型数组数据完全替换指定时间间隔内自定义交易品种的价格历史
方法2 通过socket 直接获取,
socket 需要自己进行封装对接。
两种方法各有优缺点。
总的来说MT5对外界敞开了怀抱,欢迎大家加入MT的家庭,
客户端对接自定义产品还不够完善,期待更美好的未来。
谢谢大家
如果您觉得对你有所帮助,请赞赏,你的赞赏是我更新的动力!