ea_tick_writer

Author: Copyright 2014, MetaQuotes Software Corp.
Price Data Components
Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
ea_tick_writer
//+------------------------------------------------------------------+
//|                                               ea_tick_writer.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

int handle;
string name;
uint count;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   count=0;
   name="ea_tick_writer_"+Symbol()+"_"+strMonth(Month())+IntegerToString(Year())+".csv";
   handle=FileOpen(name,FILE_CSV|FILE_READ|FILE_WRITE,';');
   if(handle==-1) { Print("Îøèáêà îòêðûòèÿ ôàéëà  "+name); return(INIT_FAILED); }
   else
    {
     FileSeek(handle,0,SEEK_END);
     if(FileSize(handle)==0) FileWrite(handle,"time","bid","ask","spread","delta");
    }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   FileClose(handle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   datetime time=TimeCurrent();
   double bid=MarketInfo(Symbol(),MODE_BID);
   double ask=MarketInfo(Symbol(),MODE_ASK);
   double spread=(ask-bid)/Point;
   int delta=-1;
   if(count!=0) delta=GetTickCount()-count;
   FileWrite(handle,TimeToStr(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS),format(bid),format(ask),
   DoubleToStr(spread,0),IntegerToString(delta));
   
   count=GetTickCount();
  }
//+------------------------------------------------------------------+
string strMonth(int m)
 {
  switch(m)
   {
    case 1: return "January";
    case 2: return "February";
    case 3: return "March";
    case 4: return "April";
    case 5: return "May";
    case 6: return "June";
    case 7: return "July";
    case 8: return "August";
    case 9: return "September";
    case 10: return "October";
    case 11: return "November";
    case 12: return "December";
    default: return "";
   }
 }
//********************************************************************
string format(double v)
 {
  string s=DoubleToStr(v,Digits());
  int len=StringLen(s);
  for(int i=0; i<=len-1; i++)
   {
    if(StringGetCharacter(s,i)==46) StringSetCharacter(s,i,44);
   }
  return s;
 }
//********************************************************************

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