问题代码

 
我想用这个脚本下载历史上的 OHLC、分形和Zigzag指标,但当我打开csv时,我没有任何信息。
谁能告诉我其中的错误?
//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
//#property copyright ""
//#property link      ""

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
export();
  }

//+------------------------------------------------------------------+
void export() 
{ 

string file="export_"+Symbol()+"_"+Period()+".csv"; 
int f=FileOpen(file,FILE_CSV|FILE_WRITE,","); 
if(f<1) { Alert("File opening error"); return(0); }
for(int i=Bars-1;i<=0;i--)
{
FileWrite(f,TimeToStr(Time,TIME_DATE|TIME_MINUTES),Open,High,Low,Close ,iFractals(Symbol(),0,1,i),iFractals(Symbol(),0,2,i),iCustom(Symbol(), 

0,"ZigZag",0,i),iCustom(Symbol(),0, "ZigZag",1,i));
}


Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
FileFlush(f); 
FileClose(f); 
}
 
我还创建了以下专家,但并没有像前面的脚本那样向我显示数据
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   start();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
 
 void export() 
{ 

string file="export_"+Symbol()+"_"+Period()+".csv"; 
int f=FileOpen(file,FILE_CSV|FILE_WRITE,","); 
if(f<1) { Alert("File opening error"); return(0); }
for(int i=Bars-1;i<=0;i--)
{
FileWrite(f,TimeToStr(Time,TIME_DATE|TIME_MINUTES),Open,High,Low,Close ,iFractals(Symbol(),0,1,i),iFractals(Symbol(),0,2,i),iCustom(Symbol(), 0,"ZigZag",0,i),iCustom(Symbol(),0, "ZigZag",1,i));
}


Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
FileFlush(f); 
FileClose(f); 
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
export();

//----
//Alert(ArraySize(norepeats) + ArraySize(morerepeats));
   return(0);
 }
//+------------------------------------------------------------------+
 
burnssss:
我想用这个脚本下载历史上的OHLC、分形和Zigzag指标,但当我打开csv时,我没有任何信息。
谁能告诉我其中的错误?

请使用论坛搜索 . .

https://www.mql5.com/en/forum/147170

. . . .和文件

 

我以这种方式进行了组合,但它给我带来了错误。我不明白为什么我得到的文件没有任何数据

//#property copyright ""
//#property link      ""

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
export();
  }

//+------------------------------------------------------------------+
void export() 
{ 

string file="export_"+Symbol()+"_"+Period()+".csv"; 
int f=FileOpen(file,FILE_CSV|FILE_READ,","); 
if(f<1) { Alert("File opening error"); return(0); }
for(int i=Bars-1;i<=0;i--)
{
FileWrite(f,TimeToStr(Time,TIME_DATE|TIME_MINUTES),Open,High,Low,Close ,iFractals(Symbol(),0,1,i),iFractals(Symbol(),0,2,i),iCustom(Symbol(), 

0,"ZigZag",0,i),iCustom(Symbol(),0, "ZigZag",1,i));
}


Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
FileFlush(f); 
FileClose(f); 
}
 

1) >=

for(int i=Bars-1;i<=0;i--)

2)FILE_WRITE或 FILE_READ|FILE_WRITE

FileOpen(file,FILE_CSV|FILE_READ,","); 

3) 你知道EMPTY_VALUE 吗(ZZ和Fractals可能有这个功能)? (空值不会被画出来或显示在DataWindow中。默认情况下,空值是EMPTY_VALUE)

4)在文件关闭时,数据会自动刷新到磁盘,所以在调用 FileClose()函数之前不需要调用FileFlush()函数

 

我做了这些修改,文件只得到一个事实。

1970.01.01 00:00,,,,, 0,0,0,2147483647.

我想不出更多

//#property copyright ""
//#property link      ""

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
export();
  }

//+------------------------------------------------------------------+
void export() 
{ 

string file="export_"+Symbol()+"_"+Period()+".csv"; 
int f=FileOpen(file,FILE_READ|FILE_WRITE,","); 
if(f<1) { Alert("File opening error"); return(0); }
for(int i=Bars-1;i>=0;i--)
{
FileWrite(f,TimeToStr(Time,TIME_DATE|TIME_MINUTES),Open,High,Low,Close ,iFractals(Symbol(),0,1,i),iFractals(Symbol(),0,2,i),iCustom(Symbol(), 

0,"ZigZag",0,i),iCustom(Symbol(),0, "ZigZag",1,i));
FileClose(f);
}


Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
FileClose(f); 
}

 
burnssss:

我做了这些修改,文件只得到一个事实。

1970.01.01 00:00,,,,, 0,0,0,2147483647.

我想不出更多

如果你打开一个文件,写到它,关闭它,然后再次打开它,写一些更多的数据,新的数据将被写到哪里? 文件中的什么地方?
 

在你打开这个话题的几个小时前

另一个话题也与你的主题有关

你没看吗? 保存图表数据到文件

 
RaptorUK:
如果你打开一个文件,写到它,关闭它,然后再次打开它,写一些更多的数据,新的数据将被写到哪里? 文件的什么地方?


在代码中,我认为我使用了正确的步骤。我认为你应该把所有的数据下载到一个文件中。Csv,但不明白我为什么要这样做。
 

我试着创建了一个专家,或多或少有些类似的代码,我写了一个文件,例如每月的数据

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,1.1614,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,2147483647

1970.01.01 00:00,,,,,1.4104,0,0,2147483647

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.1688,0,0

1970.01.01 00:00,,,,,1.2495,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.1192,0,0

1970.01.01 00:00,,,,,1.2315,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.1069,1.1069,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.2894,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.3161,0,0,1.3161

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.2351,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.4535,0,1.4535,1.4535

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.3,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.3353,1.2596,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.0344,1.0344,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.1537,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.0608,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.1216,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,1.079,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,0,0,0,0

1970.01.01 00:00,,,,,1.2401,0,1.2401,1.2401

但是没有再下载1970年的数据。

我们使用的代码如下。

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   start();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
 
 void export() 
{ 

string file="export_"+Symbol()+"_"+Period()+".csv"; 
int f=FileOpen(file,FILE_CSV|FILE_WRITE,","); 
if(f<1) { Alert("File opening error"); return(0); }
for(int i=Bars-1;i>=0;i--)
{
FileWrite(f,TimeToStr(Time,TIME_DATE|TIME_MINUTES),Open,High,Low,Close ,iFractals(Symbol(),0,1,i),iFractals(Symbol(),0,2,i),iCustom(Symbol(), 0,"ZigZag",0,i),iCustom(Symbol(),0, "ZigZag",1,i));
}


Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
FileClose(f); 
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
export();

//----
//Alert(ArraySize(norepeats) + ArraySize(morerepeats));
   return(0);
 }
//+------------------------------------------------------------------+
 
burnssss:

在代码中,我认为我使用了正确的步骤。我认为你应该在一个文件中下载所有的数据。Csv,但我不明白为什么要这样做。
你没有回答我的简单问题,你想把新数据放在文件的什么地方?. .