Rahul Shaji Parmeshwar: I cannot figure out how to add column names to my csv file when mql4 outputs it. Has anyone managed to get around this?
int f=FileOpen(file,FILE_CSV|FILE_WRITE,","); if … for(int i=0;i<Bars;i++) FileWrite(…} FileClose(f);
There is no getting around anything: PICNIC. Open the file, write the headers, write the data. Close the file. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help (2017.04.21)
@William Roeder Thank you for your clarification, I managed to figure it out with your help. Now however, I need to split the date from the time and since mql4 outputs the date and time as a string it is a bit difficult. Could you provide any clarity on this please? I've also attached the fixed code for the data exporter with corrected column names in case anybody needs to use it in the future.
int OnInit() { Switch = TimeCurrent(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(TimeCurrent() > (Switch+30)){ string file="export_"+Symbol()+"_"+Period()+".csv"; int f=FileOpen(file,FILE_CSV|FILE_WRITE,","); if(f<1) { Alert("File opening error"); return(0); } if(f>0){ FileSeek(f,0,SEEK_SET); FileWrite(f,"DateTime","Open","High","Low","Close","Volume","Spread"); } for(int i=0;i<Bars;i++) { FileWrite(f,StrToTime(Time[i]), Open[i],High[i],Low[i],Close[i],Volume[i],Spread); } Alert("Export "+Symbol()+" finished. Exported: "+Bars+" records"); FileFlush(f); FileClose(f); Switch = TimeCurrent(); } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, I cannot figure out how to add column names to my csv file when mql4 outputs it. Has anyone managed to get around this?
My EA outputs the chart data every 30 seconds in a CSV, the idea is then to be able to process this in python, column names would be very helpful for this. Can someone please take a look at this?
Thank you.