CSV Exporter

Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
CSV Exporter
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+


static datetime Switch;
int x;
input int    UpdateTime  =900; // after x seconds EA will run again.
input int    CandleCount  =133; // EA will export y candles only. It will rewrite on existing cvs file. 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   Switch = TimeCurrent();
   x = 1;
//---
   return(INIT_SUCCEEDED);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlRates OHLC[];
   MqlDateTime mdt;
   TimeCurrent(mdt);

   string sSymbol=Symbol();
   string  sPeriod=EnumToString(Period());
   string  ExtFileName;
   int copiedOHLC=CopyRates(NULL,0,0,CandleCount,OHLC);  // 288 bars per day on M5
   MqlRates PriceInfo[];
   ArraySetAsSeries(PriceInfo,true);
   int PriceData = CopyRates(_Symbol,_Period,0,3,PriceInfo);
   if(TimeCurrent() > (Switch+x))
     {
      ExtFileName=sSymbol;
      StringConcatenate(ExtFileName,sSymbol,"_",sPeriod,".CSV");



      int mySpreadsheetHandle = FileOpen(ExtFileName,FILE_WRITE|FILE_CSV|FILE_ANSI);
      FileSeek(mySpreadsheetHandle,0,SEEK_END);

      for(int i=1; i<=CandleCount-1; i++)
        {

         FileWrite(mySpreadsheetHandle,OHLC[i].close);  //_Symbol,OHLC[i].time, OHLC[i].time, OHLC[i].open, OHLC[i].high, , OHLC[i].tick_volume , OHLC[i].time,
         FileSeek(mySpreadsheetHandle,0,SEEK_END);
        }
      FileClose(mySpreadsheetHandle);
      Switch = TimeCurrent();
      x = UpdateTime;
     }
   Comment(" CSV Exporter ae running ... ");
  }
//+------------------------------------------------------------------+

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 ---