PROBLEM CODE - page 3

 
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?
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));
}
  1. Last argument in FileOpen is an int, not a string.
  2. You can't write arrays using FileWrite.
  3. Loop previously mentioned
 
I have developed the code to download OHLC data, fractal and zigzag, but due to the large amount of data, in M1 would choose the date from which to start downloading.
 
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| 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 have developed the code to download OHLC data, fractal and zigzag, but due to the large amount of data, in M1 would choose the date from which to start downloading.
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));
}

So what do you need to do it is not start writing from Bars-1

make a condition if time bar i > your date go filewrite....

 
deVries:

Entonces, ¿qué hay que hacer no es empezar a escribir de Bares-1

hacer una condición si barra de tiempo i> tu cita FILEWRITE ....


i dont understand because i am amateur in mql4. Could you give me an example?

What I need is, instead of starting to download data from 1971 for example, start downloading in 2009

 
burnssss:


i dont understand because i am amateur in mql4. Could you give me an example?

What I need is, instead of starting to download data from 1971 for example, start downloading in 2009


how do you get the time of a candle ??

if(Time[i]>= D'2004.01.01 00:00') FileWrite(f,TimeToStr(Time,TIM.......                                        // New Year'2004
 
In the following part of code that should change to get the zigzag of 13?

I note that I download zigzag parameter is 12 and would like to download the zigzag parameter 13

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));
}

Many thanks

 

Good,

some solution to my question?

thank you very much

 
burnssss: I note that I download zigzag parameter is 12 and would like to download the zigzag parameter 13
You are not passing ANY parameters to zigzag. If you don't want the defaults, pass all three. Detailed explanation of iCustom - MQL4 forum
 

Try this one, seems to work fine.

You will find the written file in your metatrader/tester/files folder after backtesting this expert.

Warning! I am not a programmer, so this bug may contain working code parts. :)

//+------------------------------------------------------------------+
//|                                                        burns.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net"

/*
if this mode parameter is zero, the indicator values of the previous bar 
will be written to file, instead of their last known positon
*/
extern int mode=1;
int bartime;
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){
 Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records");  
 return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
 if(bartime==Time[0]) return(0);
 bartime=Time[0];
 double value[7];
 string file="export_"+Symbol()+"_"+Period()+".csv"; 
 int f=FileOpen(file,FILE_CSV|FILE_READ|FILE_WRITE,","); 
 if(f<0) {Alert("File opening error");return(0);}
 
 value[0]=Open[1];
 value[1]=High[1];
 value[2]=Low[1];
 value[3]=Close[1];
 
 if(mode!=0) {
  value[4]=lastfrup();
  value[5]=lastfrdn();
  value[6]=lastzz();
 }
 else {
  value[4]=iFractals(NULL,0,MODE_UPPER,1);
  value[5]=iFractals(NULL,0,MODE_LOWER,1);
  value[6]=iCustom(NULL,0,"ZigZag",12,5,3,0,1);
 }
 
 string sum=TimeToStr(Time[1],TIME_DATE|TIME_MINUTES);
 for(int j=0; j<7; j++) {
  sum=sum+","+DoubleToStr(value[j],Digits);
 }
 FileSeek(f,0,SEEK_END);
 FileWrite(f,sum);
 FileClose(f);
 return(0);
}
//+------------------------------------------------------------------+
double lastfrup() {
 for(int i=1; i<Bars-1; i++) {
  if(iFractals(NULL,0,MODE_UPPER,i)!=0) break;
 }
 return(iFractals(NULL,0,MODE_UPPER,i));
}
//+------------------------------------------------------------------+
double lastfrdn() {
 for(int i=1; i<Bars-1; i++) {
  if(iFractals(NULL,0,MODE_LOWER,i)!=0) break;
 }
 return(iFractals(NULL,0,MODE_LOWER,i));
}
//+------------------------------------------------------------------+
double lastzz() {
 for(int i=1; i<Bars-1; i++) {
  if(iCustom(NULL,0,"ZigZag",12,5,3,0,i)!=0) break;
 }
 return(iCustom(NULL,0,"ZigZag",12,5,3,0,i));
}
Reason: