Why my tick export indicator doesn't work ?

 

My indicator below only creates a blank file:

//+------------------------------------------------------------------+
//|                                                 Export Ticks.mq4 |
//|                               Copyright © 2010, Forexgenuine.com |
//|                                          http://forexgenuine.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Forexgenuine.com"
#property link      "http://forexgenuine.com"

#property indicator_chart_window

// File identificator
int file;
 
// Tick count for flushing each 1024 ticks
int flushCount = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
// Open the file for writing
   file = FileOpen(Symbol() + "-Ticks.csv",FILE_WRITE | FILE_CSV,";");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   // Close the file
   FileClose(file);
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   FileWrite(file, TimeToStr(TimeCurrent(),TIME_DATE | TIME_SECONDS), 
             Bid, 
             Ask, 
             iVolume(Symbol(), NULL, 0));
 
   flushCount++;
   if (flushCount == 1024) {
      FileFlush(file);
      flushCount = 0;
   }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Just used your code and it works here is the output

2010.09.23 20:56:20;132.51;132.561;143

2010.09.23 20:56:29;132.505;132.556;144

2010.09.23 20:56:30;132.5;132.551;145

2010.09.23 20:56:30;132.504;132.555;146

2010.09.23 20:56:32;132.508;132.559;147

2010.09.23 20:56:40;132.512;132.563;148

2010.09.23 20:56:47;132.503;132.547;149

2010.09.23 20:56:48;132.48;132.531;151

2010.09.23 20:56:49;132.472;132.523;152

2010.09.23 20:56:52;132.476;132.527;153

You problably dont know here to look for the file, it is on the metatrader \expert \ files folder

 
BillyJoe:

Just used your code and it works here is the output

2010.09.23 20:56:20;132.51;132.561;143

2010.09.23 20:56:29;132.505;132.556;144

2010.09.23 20:56:30;132.5;132.551;145

2010.09.23 20:56:30;132.504;132.555;146

2010.09.23 20:56:32;132.508;132.559;147

2010.09.23 20:56:40;132.512;132.563;148

2010.09.23 20:56:47;132.503;132.547;149

2010.09.23 20:56:48;132.48;132.531;151

2010.09.23 20:56:49;132.472;132.523;152

2010.09.23 20:56:52;132.476;132.527;153

You problably dont know here to look for the file, it is on the metatrader \expert \ files folder

I looked indeed in this directory and found EURUSD-Ticks.csv. But it's always empty. I am using alpari one 1 min US chart, I did drag and drop on main chart, did I do something else wrong ?
 

the file looks empty because before you open the file you need to removed the indicator from the chart or closed metatrader, the reason is because you have the file closed on the deinit () and if you try to open the file with the indicator running you get a file ascess error.

if you still have this problem is because the file is damaged, close metatrader delete all the files form the FILES forlder open metatrader run your expert and the closed metatrader again and check the file

int deinit()
  {
//----
   // Close the file
   FileClose(file);
 
//---- 

return(0);

 
BillyJoe:

the file looks empty because before you open the file you need to removed the indicator from the chart or closed metatrader, the reason is because you have the file closed on the deinit () and if you try to open the file with the indicator running you get a file ascess error.

if you still have this problem is because the file is damaged, close metatrader delete all the files form the FILES forlder open metatrader run your expert and the closed metatrader again and check the file

return(0);


hi I'm not sure to understand. Finally when I delete the indicator THEN only the data is written to the file. But that's not what I want: I want the data to be written in real time. Is it because of the buffer maybe ?
 

You wait 1024 ticks before you force the data to the file (flush)

Are you waiting that long to see if it "works"?

 

You wait 1024 ticks before you force the data to the file (flush)

Are you waiting that long to see if it "works"?

 

You wait 1024 ticks before you force the data to the file (flush)

Are you waiting that long to see if it "works"?

Reason: