请教如何将MT5中开单或平单的数据,都写到本地EXCEL文件中 新评论 bingru 2023.08.22 03:13 请教一下,我根据MT4的程序,改MQL5后的代码如下,但在编译时,报 “ function 'CopyFileW' must have a body ” 错误,请问是什么原因? #property copyright "San Jiao" #property link "http://www.abc.com" #property version "1.00" int CopyFileW(string a0,string a1,int a2); bool CreateDirectoryW(string a0,int a1); input string 间隔符="*"; string FILES文件夹路径=""; string FILES文件夹路径2; string 中转路径=""; string 中转路径2=""; int OnInit() { return(0); } void OnTick() { if(中转路径=="") { CreateDirectoryW("C:\wenjianjia",0); 中转路径2="C:\wenjianjia"; } else 中转路径2=中转路径; while(true) { string 中转文件名=DoubleToString(AccountInfoInteger(ACCOUNT_LOGIN),0); int handle; handle=FileOpen(中转文件名+".csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符); if(handle>0) { for(int i=0;i<PositionsTotal();i++) { ulong ticket=PositionGetTicket(i); string ordsymbol = PositionGetString(POSITION_SYMBOL); string ordcom = PositionGetString(POSITION_COMMENT); long ordmagic = PositionGetInteger(POSITION_MAGIC); double ordslp = PositionGetDouble(POSITION_SL); double ordtpp = PositionGetDouble(POSITION_TP); double ordoop = PositionGetDouble(POSITION_PRICE_OPEN); long ordtype = PositionGetInteger(POSITION_TYPE); double ordlot = PositionGetDouble(POSITION_VOLUME); double ordcp = PositionGetDouble(POSITION_PRICE_CURRENT); datetime t2 = PositionGetInteger(POSITION_TIME); ulong ordtk = PositionGetInteger(POSITION_TICKET); double xx = PositionGetDouble(POSITION_PROFIT); double yy = PositionGetDouble(POSITION_SWAP); if(PositionGetTicket(i)>0) { FileWrite(handle,ordtk,ordsymbol,ordtype,ordlot,ordslp,ordtpp,ordcom,ordmagic, t2-TimeCurrent()+TimeLocal(),ordoop,SymbolInfoDouble(ordsymbol,SYMBOL_TRADE_TICK_VALUE)); } } FileClose(handle); } handle=FileOpen(中转文件名+"2.csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符); if(handle>0) { int tk=0; datetime t1=0; HistorySelect(0,TimeCurrent()); for(int i=HistoryDealsTotal()-1;i>=0;i--) { tk = HistoryDealGetTicket(i); int aa1 = HistoryDealGetInteger(tk,DEAL_POSITION_ID); string aa2 = HistoryDealGetString(tk,DEAL_SYMBOL); int aa3 = HistoryDealGetInteger(tk,DEAL_TYPE); double aa4 = HistoryDealGetDouble(tk,DEAL_VOLUME); double aa5 = HistoryDealGetDouble(tk,DEAL_SL); double aa6 = HistoryDealGetDouble(tk,DEAL_TP); string aa7 = HistoryDealGetString(tk,DEAL_COMMENT); int aa8 = HistoryDealGetInteger(tk,DEAL_MAGIC); int aa9 = HistoryDealGetInteger(tk,DEAL_TIME); double aa10 = HistoryDealGetDouble(tk,DEAL_PRICE); if(HistoryDealGetTicket(i)>0) { FileWrite(handle,aa1,aa2,aa3,aa4,aa5,aa6,aa7,aa8,aa9-TimeCurrent()+TimeLocal(),aa10); } } FileClose(handle); } if(FILES文件夹路径!="") FILES文件夹路径2=FILES文件夹路径; else FILES文件夹路径2=TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files"; int t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+".csv",中转路径2+"\\"+中转文件名+".csv",0); t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+"2.csv",中转路径2+"\\"+中转文件名+"2.csv",0); /* if(!(!IsStopped() && IsExpertEnabled() && IsTesting()==false && IsOptimization()==false)) return; */ Sleep(300); } } // ontick end void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- OnTick(); } ABC Network - ABC.com abc.com Watch the ABC Shows online at abc.com. Get exclusive videos and free episodes. 新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 初学者的问题 MQL5 MT5 MetaTrader 5 vps服务器 bingru 2023.08.22 06:55 #1 有人知道吗? Zhang Fengqun 2023.08.22 13:24 #2 【如何防止机器人误判】讨论代码时请使用代码表述功能 - 技术指标 - MQL5 算法交易论坛 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 免费24小时外汇VPS 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
bingru 2023.08.22 03:13 请教一下,我根据MT4的程序,改MQL5后的代码如下,但在编译时,报 “ function 'CopyFileW' must have a body ” 错误,请问是什么原因? #property copyright "San Jiao" #property link "http://www.abc.com" #property version "1.00" int CopyFileW(string a0,string a1,int a2); bool CreateDirectoryW(string a0,int a1); input string 间隔符="*"; string FILES文件夹路径=""; string FILES文件夹路径2; string 中转路径=""; string 中转路径2=""; int OnInit() { return(0); } void OnTick() { if(中转路径=="") { CreateDirectoryW("C:\wenjianjia",0); 中转路径2="C:\wenjianjia"; } else 中转路径2=中转路径; while(true) { string 中转文件名=DoubleToString(AccountInfoInteger(ACCOUNT_LOGIN),0); int handle; handle=FileOpen(中转文件名+".csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符); if(handle>0) { for(int i=0;i<PositionsTotal();i++) { ulong ticket=PositionGetTicket(i); string ordsymbol = PositionGetString(POSITION_SYMBOL); string ordcom = PositionGetString(POSITION_COMMENT); long ordmagic = PositionGetInteger(POSITION_MAGIC); double ordslp = PositionGetDouble(POSITION_SL); double ordtpp = PositionGetDouble(POSITION_TP); double ordoop = PositionGetDouble(POSITION_PRICE_OPEN); long ordtype = PositionGetInteger(POSITION_TYPE); double ordlot = PositionGetDouble(POSITION_VOLUME); double ordcp = PositionGetDouble(POSITION_PRICE_CURRENT); datetime t2 = PositionGetInteger(POSITION_TIME); ulong ordtk = PositionGetInteger(POSITION_TICKET); double xx = PositionGetDouble(POSITION_PROFIT); double yy = PositionGetDouble(POSITION_SWAP); if(PositionGetTicket(i)>0) { FileWrite(handle,ordtk,ordsymbol,ordtype,ordlot,ordslp,ordtpp,ordcom,ordmagic, t2-TimeCurrent()+TimeLocal(),ordoop,SymbolInfoDouble(ordsymbol,SYMBOL_TRADE_TICK_VALUE)); } } FileClose(handle); } handle=FileOpen(中转文件名+"2.csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符); if(handle>0) { int tk=0; datetime t1=0; HistorySelect(0,TimeCurrent()); for(int i=HistoryDealsTotal()-1;i>=0;i--) { tk = HistoryDealGetTicket(i); int aa1 = HistoryDealGetInteger(tk,DEAL_POSITION_ID); string aa2 = HistoryDealGetString(tk,DEAL_SYMBOL); int aa3 = HistoryDealGetInteger(tk,DEAL_TYPE); double aa4 = HistoryDealGetDouble(tk,DEAL_VOLUME); double aa5 = HistoryDealGetDouble(tk,DEAL_SL); double aa6 = HistoryDealGetDouble(tk,DEAL_TP); string aa7 = HistoryDealGetString(tk,DEAL_COMMENT); int aa8 = HistoryDealGetInteger(tk,DEAL_MAGIC); int aa9 = HistoryDealGetInteger(tk,DEAL_TIME); double aa10 = HistoryDealGetDouble(tk,DEAL_PRICE); if(HistoryDealGetTicket(i)>0) { FileWrite(handle,aa1,aa2,aa3,aa4,aa5,aa6,aa7,aa8,aa9-TimeCurrent()+TimeLocal(),aa10); } } FileClose(handle); } if(FILES文件夹路径!="") FILES文件夹路径2=FILES文件夹路径; else FILES文件夹路径2=TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files"; int t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+".csv",中转路径2+"\\"+中转文件名+".csv",0); t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+"2.csv",中转路径2+"\\"+中转文件名+"2.csv",0); /* if(!(!IsStopped() && IsExpertEnabled() && IsTesting()==false && IsOptimization()==false)) return; */ Sleep(300); } } // ontick end void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- OnTick(); } ABC Network - ABC.com abc.com Watch the ABC Shows online at abc.com. Get exclusive videos and free episodes. 新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 初学者的问题 MQL5 MT5 MetaTrader 5 vps服务器
请教一下,我根据MT4的程序,改MQL5后的代码如下,但在编译时,报 “ function 'CopyFileW' must have a body ” 错误,请问是什么原因?
#property copyright "San Jiao"
#property link "http://www.abc.com"
#property version "1.00"
int CopyFileW(string a0,string a1,int a2);
bool CreateDirectoryW(string a0,int a1);
input string 间隔符="*";
string FILES文件夹路径="";
string FILES文件夹路径2;
string 中转路径="";
string 中转路径2="";
int OnInit()
{
return(0);
}
void OnTick()
{
if(中转路径=="")
{
CreateDirectoryW("C:\wenjianjia",0);
中转路径2="C:\wenjianjia";
}
else
中转路径2=中转路径;
while(true)
{
string 中转文件名=DoubleToString(AccountInfoInteger(ACCOUNT_LOGIN),0);
int handle;
handle=FileOpen(中转文件名+".csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符);
if(handle>0)
{
for(int i=0;i<PositionsTotal();i++)
{
ulong ticket=PositionGetTicket(i);
string ordsymbol = PositionGetString(POSITION_SYMBOL);
string ordcom = PositionGetString(POSITION_COMMENT);
long ordmagic = PositionGetInteger(POSITION_MAGIC);
double ordslp = PositionGetDouble(POSITION_SL);
double ordtpp = PositionGetDouble(POSITION_TP);
double ordoop = PositionGetDouble(POSITION_PRICE_OPEN);
long ordtype = PositionGetInteger(POSITION_TYPE);
double ordlot = PositionGetDouble(POSITION_VOLUME);
double ordcp = PositionGetDouble(POSITION_PRICE_CURRENT);
datetime t2 = PositionGetInteger(POSITION_TIME);
ulong ordtk = PositionGetInteger(POSITION_TICKET);
double xx = PositionGetDouble(POSITION_PROFIT);
double yy = PositionGetDouble(POSITION_SWAP);
if(PositionGetTicket(i)>0)
{
FileWrite(handle,ordtk,ordsymbol,ordtype,ordlot,ordslp,ordtpp,ordcom,ordmagic,
t2-TimeCurrent()+TimeLocal(),ordoop,SymbolInfoDouble(ordsymbol,SYMBOL_TRADE_TICK_VALUE));
}
}
FileClose(handle);
}
handle=FileOpen(中转文件名+"2.csv",FILE_CSV|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ,间隔符);
if(handle>0)
{
int tk=0;
datetime t1=0;
HistorySelect(0,TimeCurrent());
for(int i=HistoryDealsTotal()-1;i>=0;i--)
{
tk = HistoryDealGetTicket(i);
int aa1 = HistoryDealGetInteger(tk,DEAL_POSITION_ID);
string aa2 = HistoryDealGetString(tk,DEAL_SYMBOL);
int aa3 = HistoryDealGetInteger(tk,DEAL_TYPE);
double aa4 = HistoryDealGetDouble(tk,DEAL_VOLUME);
double aa5 = HistoryDealGetDouble(tk,DEAL_SL);
double aa6 = HistoryDealGetDouble(tk,DEAL_TP);
string aa7 = HistoryDealGetString(tk,DEAL_COMMENT);
int aa8 = HistoryDealGetInteger(tk,DEAL_MAGIC);
int aa9 = HistoryDealGetInteger(tk,DEAL_TIME);
double aa10 = HistoryDealGetDouble(tk,DEAL_PRICE);
if(HistoryDealGetTicket(i)>0)
{
FileWrite(handle,aa1,aa2,aa3,aa4,aa5,aa6,aa7,aa8,aa9-TimeCurrent()+TimeLocal(),aa10);
}
}
FileClose(handle);
}
if(FILES文件夹路径!="")
FILES文件夹路径2=FILES文件夹路径;
else
FILES文件夹路径2=TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files";
int t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+".csv",中转路径2+"\\"+中转文件名+".csv",0);
t=CopyFileW(FILES文件夹路径2+"\\"+中转文件名+"2.csv",中转路径2+"\\"+中转文件名+"2.csv",0);
/*
if(!(!IsStopped() && IsExpertEnabled() && IsTesting()==false && IsOptimization()==false))
return;
*/
Sleep(300);
}
} // ontick end
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
OnTick();
}