Export metatrader 5 to excel

 
Hi,
Need to export the prices of a currency metatrader 5 for an excel table.
Have any function for this?
grateful
 
ilson:
Hi,
Need to export the prices of a currency metatrader 5 for an excel table.
Have any function for this?
grateful

Try this.


Make a new indicator and copy this code in the file.


//+------------------------------------------------------------------+
//|                                                         Data.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 1
#property indicator_plots   1

//--- parameters for writing data to the file
input string             InpFileName      = "Bars.csv"; // file name
input string             InpDirectoryName = "Data";   // directory name

int nfile_handle;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
   {
  
   return(INIT_SUCCEEDED);
   }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   {

// CHECK VOOR EEN NIEUWE (MINUTEN) BAR
//------------------------------------

// Rates structure array voor prijs data van de laatste 2 minuten.  
   MqlRates mrate[2];  
   
// Rates structure voor de intraday data.               
   CopyRates(Symbol(), Period(), 0, 2, mrate);

// NIEUWE BAR CHECK.
//------------------
   static double   dBar_Open;     
   static double   dBar_High;
   static double   dBar_Low;
   static double   dBar_Close;
   static long     lBar_Volume;
   static datetime nBar_Time;

// Boolean voor de bevestiging van een nieuwe BAR.
   bool bStart_NewBar = false;

// Check if the price data has changed tov the previous bar.   
   if(mrate[0].open != dBar_Open || mrate[0].high != dBar_High || mrate[0].low != dBar_Low || mrate[0].close != dBar_Close || mrate[0].tick_volume != lBar_Volume || mrate[0].time != nBar_Time || prev_calculated == 0)
         {
         bStart_NewBar = true;         
     
         dBar_Open   = mrate[0].open;      
         dBar_High   = mrate[0].high;
         dBar_Low    = mrate[0].low;
         dBar_Close  = mrate[0].close;                 
         lBar_Volume = mrate[0].tick_volume;
         nBar_Time   = mrate[0].time;
         }

// Check if the indicator has not yet been calculated or if a new bar has formed.   
   if(bStart_NewBar == true || prev_calculated == 0)
         {

// Number of BARS to copy   
         static int nHistoryPeriod = 1;
         nHistoryPeriod = Bars(Symbol(), PERIOD_M1) - 1;

// Data array for storage.         
         datetime aData_Time[];
         double   aData_Open[];
         double   aData_High[];
         double   aData_Low[];
         double   aData_Close[]; 
         long     aData_Volume[]; 

// Copy data to array.              
         CopyTime(Symbol(),       Period(), 1, nHistoryPeriod, aData_Time);
         CopyOpen(Symbol(),       Period(), 1, nHistoryPeriod, aData_Open);
         CopyHigh(Symbol(),       Period(), 1, nHistoryPeriod, aData_High);
         CopyLow(Symbol(),        Period(), 1, nHistoryPeriod, aData_Low);
         CopyClose(Symbol(),      Period(), 1, nHistoryPeriod, aData_Close);
         CopyTickVolume(Symbol(), Period(), 1, nHistoryPeriod, aData_Volume);

      
// Check/create CSV file      
         nfile_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_READ|FILE_WRITE|FILE_CSV);   

// Check if file is valid.         
         if(nfile_handle != INVALID_HANDLE)
               {
        
// Check array size.
               int nArray_Size = ArraySize(aData_Close);
                        
// Loop calculation.
               for(int i = 0; i < nArray_Size; i++)
                     {

// Write the values to the Excel file.                                  
                     FileWrite(nfile_handle, aData_Time[i], aData_Open[i], aData_High[i], aData_Low[i], aData_Close[i], aData_Volume[i]);                    
                     }

// Melding geven dat de data naar het bestand is geschreven.
               Alert("De DATA is naar het bestand geschreven!");
      
// Close the file.
               FileClose(nfile_handle);          
               }
         }
   


//--- return value of prev_calculated for next call
   return(rates_total);
   }
 
snelle_moda:

Try this.


Make a new indicator and copy this code in the file.


Thank snelle moda,
It worked,
I tried to make an adjustment in the code to change the directory, but gave error:
Its change the format of the currency change to (,) Example (.): R $ 50.25

//--- parameters for writing data to the file
input string             InpFileName      = "Bars.csv"; // file name
input string             InpDirectoryName = "D://Data";   // directory name <-----------------------------------------



translation with google translator

 
ilson:

Thank snelle moda,
It worked,
I tried to make an adjustment in the code to change the directory, but gave error:
Its change the format of the currency change to (,) Example (.): R $ 50.25



translation with google translator


Check this link for the file functions for writing files.


https://www.mql5.com/en/docs/files

Documentation on MQL5: File Functions
Documentation on MQL5: File Functions
  • www.mql5.com
File Functions - Reference on algorithmic/automated trading language for MetaTrader 5
 
ilson:

Thank snelle moda,
It worked,
I tried to make an adjustment in the code to change the directory, but gave error:
Its change the format of the currency change to (,) Example (.): R $ 50.25



translation with google translator


hi ilson 

may i know the formula in excel u use to get hi low ask bid? i also use MT5