//+------------------------------------------------------------------+ //| 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; } //********************************************************************