Remember: OHLC data is received from the bar! Example for PERIOD_M1
//+------------------------------------------------------------------+ //| OHLC to csv.mq5 | //| Copyright © 2020, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2020, Vladimir Karputov" #property version "1.00" //--- input parameters input string InpFileName="filewrite-7.csv"; //--- int filehandle=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- filehandle=FileOpen(InpFileName,FILE_WRITE|FILE_READ|FILE_CSV); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- FileClose(filehandle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- MqlRates rates[]; datetime time=(datetime)SymbolInfoInteger(Symbol(),SYMBOL_TIME); int result=CopyRates(Symbol(),Period(),time-65,time,rates); if(result>0) { for(int i=0; i<result; i++) { string m_row=""; StringAdd(m_row,TimeToString(rates[i].time)); StringAdd(m_row,StringFormat("\t%G",rates[i].open)); StringAdd(m_row,StringFormat("\t%G",rates[i].high)); StringAdd(m_row,StringFormat("\t%G",rates[i].close)); StringAdd(m_row,StringFormat("\t%G",rates[i].low)); FileWrite(filehandle,m_row); } } } //+------------------------------------------------------------------+
Hello Vladimir Karputov and Rezashahabi
I am new at MQL5/MT5.
Thanks for the code, when I compile it in MQL5 it works without any problem but I cound't find the "filewrite-7.csv" folder in my file system. Could you please guide me on this?
Hello Vladimir Karputov and Rezashahabi
I am new at MQL5/MT5.
Thanks for the code, when I compile it in MQL5 it works without any problem but I cound't find the "filewrite-7.csv" folder in my file system. Could you please guide me on this?
Files (unless given a path) are created in the MQL5\Files directory.
More specifically in C:\Users\<username>\AppData\Roaming\MetaQuotes\Terminal\<SomeLongCodeFolderName>\MQL5\Files.
The "Open Data Folder" option in the Meta Editor : File menu takes you to the folder containing the MQL5 directory.
Hope that helps...
Martyn

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi!
im writnig a kinda expert that get every price change and store it to a array and export it to a csv file!
i have some problem to not too copy duplicated data, but i dont get it why its happening
can any one help me pleas