data exporter - candle info to excel or txt file

 

hi below code is export data from mt4 to txt or csv , (1) i want to have all number in 5 digit , now when last number is 0 its donot write it exmpale it write 1.22320 -->  1.2232 ?

And also (2) how to make to get 200000 candle info or more candle?

and one more quastion (3) right now when the file is open it donot make change in file and the file must be close that this indicator export new data in it how to make it possible that when the file is open it make new candle information on the file?

(4) is it possible to have info in separate CELL in excel ? (right now its make all info in one CELL i mean to have for example OpenPrice in A2 ClosePrice in B2 and ...


//+------------------------------------------------------------------+
//|                                                     out_hist.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  out_hist("EURUSD",1);  // This will produce daily history for EURUSD
// Copy the above line of code for each currency pair and timeframe, and then press F5 to recompile (or restart MT4)
// First parameter must be a valid currency pair, e.g. EURUSD
// Second parameter must be valid timeframe, i.e. one of 1, 5, 15, 30, 60 (=H1), 240 (=H4), 1440 (daily), 10080 (weekly), 43200 (monthly) 
// To use the currently displayed chart: out_hist(Symbol(),Period());

  return(0);
  }
//  
int out_hist(string ccy, int tf)
{
  string fname = ccy + "," + tf + "000.csv";                         // Same folder for each TF (...\experts\files)
//string fname = "TF-" + tf + "\\" + ccy + "," + tf + "000.csv";     // Different subfolder for each timeframe
  int handle = FileOpen(fname, FILE_CSV|FILE_WRITE, ",");         // "," means that output data will be separated by commas; change if necessary
  if(handle>=0)
    {
     FileWrite(handle,"Date,Time,Open,Low,High,Close,Volume");    // This writes the Header record to the file (change or remove to suit)
     for(int i=0; i<=iBars(ccy,tf); i++)                           // Use descending date sequence
//   for(int i=iBars(ccy,tf)-1; i>=0; i--)                        // Use ascending date sequence
       {
       string date1 = TimeToStr(iTime(ccy,tf,i),TIME_DATE);
       date1 = StringSubstr(date1,5,2) + "-" + StringSubstr(date1,8,2) + "-" + StringSubstr(date1,0,4);
// NOTE: StringSubstr(date1,5,2) is the MONTH
//       StringSubstr(date1,8,2) is the DAY
//       StringSubstr(date1,0,4) is the YEAR (4 digits)
//       "-" means the separator will be a hyphen
//       So if, for example, you want to change the output date format to DD/MM/YYYY, change the above line of code to:
//     date1 = StringSubstr(date1,8,2) + "/" + StringSubstr(date1,5,2) + "/" + StringSubstr(date1,0,4);

       string time1 = TimeToStr(iTime(ccy,tf,i),TIME_MINUTES);
       FileWrite(handle, date1, time1, iOpen(ccy,tf,i), iLow(ccy,tf,i), iHigh(ccy,tf,i), iClose(ccy,tf,i), iVolume(ccy,tf,i));
// The above line writes the data to the file in the order: date, time, open, low, high, close, volume. Change the order to suit, if necessary      
       }
     FileClose(handle);
     Comment("History output complete");     // Display a comment in the upper left corner of the chart to advise that process is complete
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

(1) i want to have all number in 5 digit

DoubleToString(100,5);
https://docs.mql4.com/convert/doubletostring


(2) how to make to get 200000 candle info or more candle?

Tools > Options > Chart


(3) right now when the file is open it donot make change in file

https://docs.mql4.com/files/fileflush

DoubleToString - Conversion Functions - MQL4 Reference
DoubleToString - Conversion Functions - MQL4 Reference
  • docs.mql4.com
DoubleToString - Conversion Functions - MQL4 Reference
 
Lee Chee Tat -:

(1) i want to have all number in 5 digit

https://docs.mql4.com/convert/doubletostring


(2) how to make to get 200000 candle info or more candle?

Tools > Options > Chart


(3) right now when the file is open it donot make change in file

https://docs.mql4.com/files/fileflush

Thanks a lot,

Could you please add these that you meantion in the code 🙏🥰🥰🥰

 
Mahdi E:

Thanks a lot,

Could you please add these that you meantion in the code 🙏🥰🥰🥰

You will never learn to code, if you don't try to code it. 

Show your tries.. woking with files is easy.. if you get any problem, update the code here and I can help you.
 
hi , thanks alot, i put 
DoubleToString(100,5);

before FileWrite but still its ignore "0" when "0" is at the end of number!

i put it like this

int out_hist(string ccy, int tf)
{
  string fname = ccy + "," + tf + "000.csv";                         // Same folder for each TF (...\experts\files)
//string fname = "TF-" + tf + "\\" + ccy + "," + tf + "000.csv";     // Different subfolder for each timeframe
  int handle = FileOpen(fname, FILE_CSV|FILE_WRITE, ",");         // "," means that output data will be separated by commas; change if necessary
  if(handle>=0)
    {
    DoubleToString(100,5);
     FileWrite(handle,"Date,Time,Open,Low,High,Close,Volume");    // This writes the Header record to the file (change or remove to suit)
     for(int i=0; i<=iBars(ccy,tf); i++) 



could you please help me about ((     FileFlush    ))  what code and where i add that when file is open its work?

 
Mahdi E:
hi , thanks alot, i put 

before FileWrite but still its ignore "0" when "0" is at the end of number!

i put it like this



could you please help me about ((     FileFlush    ))  what code and where i add that when file is open its work?

DoubleToString(100,5);

alone this command is useless. You have to put the return from its convertion to some variable:


ExampleL

string myNumberWithFiveDigits = DoubleToString(100,5);


Have you ever programmed in any other computer language ? This is C Language, the example you did demonstrates you dont know the CONCEPT of programming languages.

You better study the Concepts, to later choose a language to learn. Otherwise yout mind will create a huge confusion about how programming works, which you lead you to future learning difficulties.


First what comes first, then later what comes after the first things. 

 
How to add time filter ?
(That just get info if candle for example from 8am to 8pm)
Reason: