CSV producer

Author: MojoFX
CSV producer
Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
CSV producer
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                 CSV producer.mq4 |
//|                                                           MojoFX |
//|                                                fx.studiomojo.com |
//+------------------------------------------------------------------+
#property copyright "MojoFX"
#property link      "fx.studiomojo.com"
#property show_confirm
#property show_inputs

extern int barQty = 500;
extern string fileExtension = ".txt";
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
   {
   if (barQty == 0) barQty = Bars-1; 
   
//----
   FileDelete(Symbol()+Period()+fileExtension);
   for (int i=barQty; i>0; i--)
      {
      int handle;      
      handle = FileOpen(Symbol()+Period()+fileExtension, FILE_CSV|FILE_WRITE|FILE_READ,',');      
      if (handle>0)
         {
         string mmStr,ddStr;
         if (TimeDay(Time[i])<10) ddStr="0"+TimeDay(Time[i]); else ddStr=TimeDay(Time[i]);
         if (TimeMonth(Time[i])<10) mmStr="0"+TimeMonth(Time[i]); else mmStr=TimeMonth(Time[i]);
         string dateStr = TimeYear(Time[i])+"-"+mmStr+"-"+ddStr;
         FileSeek(handle,0,SEEK_END);
         FileWrite(handle,
            dateStr,
            Symbol(),
            Open[i]*MathPow(10,Digits),
            High[i]*MathPow(10,Digits),
            Low[i]*MathPow(10,Digits),
            Close[i]*MathPow(10,Digits),
            Volume[i]);
         FileClose(handle);
         }      
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---