请教如何将MT5中开单或平单的数据,都写到本地EXCEL文件中

 

请教各位,以下是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 #:
有高手知道吗?

不用搞这么复杂,直接拼接字符串,然后写入就可以了。

 
Xiaoyu Huang #:

不用搞这么复杂,直接拼接字符串,然后写入就可以了。

请问怎么直接写入呢?请指教,谢谢!