请教如何将MT5中开单或平单的数据,都写到本地EXCEL文件中 新评论 bingru 2023.08.23 02:00 请教各位,以下是MQL5的开平仓信息写到本地EXCEL的代码,但编译的时候,报错,请教需要怎样修正,谢谢! 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(); } bingru 2023.08.30 06:27 #1 有高手知道吗? Xiaoyu Huang 2023.08.31 16:15 #2 bingru #: 有高手知道吗? 不用搞这么复杂,直接拼接字符串,然后写入就可以了。 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 免费24小时外汇VPS 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
bingru 2023.08.23 02:00 请教各位,以下是MQL5的开平仓信息写到本地EXCEL的代码,但编译的时候,报错,请教需要怎样修正,谢谢! 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(); }
请教各位,以下是MQL5的开平仓信息写到本地EXCEL的代码,但编译的时候,报错,请教需要怎样修正,谢谢!