MetaTrader 4 and data export to a file

Another question about exporting data from MT4 to files for easy data analysis in programs such as Excel was today asked on Navigator Forum. It’s time to solve this problem once and for all :)

The whole thing is simple regarding quotes data and data from indicators.

Below, I show you a sample code, which implements exporting:

void export() {

   string file="export_"+Symbol()+"_"+Period()+".csv";
   int f=FileOpen(file,FILE_CSV|FILE_WRITE,",");

   if(f<1) {
    Alert("File opening error");

   for(int i=0;i<Bars;i++) {

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



Of course nothing stops us from adding another columns in FileWrite line, e.g. indicator values – both built-in like iMA and others using iCustom.

As a result we get a CSV file, which is very easy to import to programs such as Excel.

Share with your friends:

Send us your comments

Name (required)

Email (required)


  • Facebook