PROBLEM CODE

 
I want to download historical OHLC, fractals and zigzag indicator, using this script, but when I opened the csv, I have not any information.
Can anyone tell me the error there?
//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
//#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); 
}
 
I have also created the following expert, but does not show me the data like the previous script
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| 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:
I want to download historical OHLC, fractals and zigzag indicator, using this script, but when I opened the csv, I have not any information.
Can anyone tell me the error there?

Please use the Forum search . . .

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

. . . and the documentation

 

I have combined in this way, and it gives me error. Do not understand why I get the file without any data

//#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 or FILE_READ|FILE_WRITE

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

3) Do you know about EMPTY_VALUE (ZZ and Fractals may have it) ??? (Empty values are not drawn or shown in the DataWindow. By default, empty value is EMPTY_VALUE)

4) At file closing, the data are flushed to the disk automatically, so there is no need to call the FileFlush() function before calling of the FileClose() function.

 

I made those changes, and the file gets me only one fact:

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

I can think of nothing more

//#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:

I made those changes, and the file gets me only one fact:

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

I can think of nothing more

If you open a file, write to it, close it, then open it again to write some more data where will the new data be written to ? what place in the file ?
 

A few hours before you opened this topic

another topic opend with also your subject

didn't you read it ?? Saving chart data to file

 
RaptorUK:
If you open a file, write to it, close it, then open it again to write some more data where will the new data be written to ? what place in the file ?


In the code, I think I use the right steps. I think you should download all the data in a file. Csv, but do not understand why I do this.
 

I tried creating a expert, more or less similar code, and I write a file eg monthly data

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

But no more download data from 1970.

The code we used was as follows:

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

//+------------------------------------------------------------------+
//| 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:

In the code, I think I use the right steps. I think you should download all the data in a file. Csv, but do not understand why I do this.
You didn't answer my simple question, where in the file do you want to place the new data ? if you think about that for a few minutes it will help you . . .