Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 05.04.17
Kronenchakra Kronenchakra ist offline
Gesperrter Benutzer
 
Registriert seit: Feb 2016
Ort: 2100 Österreich
Beiträge: 313
Kronenchakra befindet sich auf einem aufstrebenden Ast
Standard Binärdatei schreiben

Binärdateien haben den Vorteil, daß keine Typenumwandlungen durchgeführt werden müssen.
Sie sind daher schneller zu schreiben und zu lesen, und sie sind wesentlich kleiner als Textdateien.
Hier das Beispiel analog zu Textdatei schreiben, allerdings im Binärformat.
Wie die zwei vorgehenden Beispiele läuft dieses sowohl im MT5 als auch im MT4.
Code:
//+------------------------------------------------------------------+
//|                                            FileWriteTicksBin.mq5 |
//|                                Copyright © 2017 Ing. Otto Pauser |
//+------------------------------------------------------------------+
#property copyright   "Copyright © 2017 Ing. Otto Pauser"
#property version     "1.00"
#property description "Dieser EA schreibt die Tickdaten in eine Binärdatei"
#property description "und läuft sowohl im MT5 als auch im MT4!"
#property description "Der Symbolname wir automatisch dem Dateinamen vorgestellt."
#property description "Dateipfad und Datei werden angelegt, falls nicht vorhanden"
#property description "Eine eventuell bestehende Datei wird überschrieben"
#property description "Press <ESC> to stop recording tickdata"

//+------------------------------------------------------------------+
input string fPath = "Tickdata";    // File Path
input string fName = "Ticks.bin";   // File Name
input bool   fComm = true;          // Write to CommonFiles
//+------------------------------------------------------------------+

string   fn = fPath+"\\"+_Symbol+"_"+fName;     // full filename
int      fh,                                    // file handle
         ff = FILE_WRITE|FILE_BIN;              // file flags

struct tickStruct                   // define the structure of data
{
   datetime Time;
   double   Ask;
   double   Bid;
   int      Spread;                 // eigentlich unnötig, da Ask-Bid=Spread
};

tickStruct  tick;                   // declare a variable         

//+------------------------------------------------------------------+
int OnInit()
{
   if(fComm)                        // CommonFiles selected ?
      ff=ff|FILE_COMMON;            // merge the common flag to fileflags
      
   fh=FileOpen(fn,ff);              // try to open
   
   if(fh==INVALID_HANDLE)           // check the handle
      {
         Alert("*ERROR* creating "+fn);
         return(INIT_FAILED);
      }
      
   Comment("Recording tickdata to file: "+fn);        // information

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Comment("");               // clear information
   if(fh!=INVALID_HANDLE)     // file open ?
      FileClose(fh);          // close the file
   PlaySound("ok");
}

//+------------------------------------------------------------------+
void OnTick()
{
   MqlTick  last_tick;        // for tickvalues

   if(!SymbolInfoTick(Symbol(),last_tick)) return;    // try to get tickinfo
   
   tick.Time    =last_tick.time;                      // fill the structure with data
   tick.Ask     =last_tick.ask;
   tick.Bid     =last_tick.bid;
   tick.Spread  =(int)SymbolInfoInteger(_Symbol,SYMBOL_SPREAD); 

   FileWriteStruct(fh,tick);                          // write the structure to file
}

//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   if(id==CHARTEVENT_KEYDOWN)                   // key pressed ?
      if(lparam==27)                            // <ESC> ?
         ExpertRemove();                        // remove executes OnDeinit first, then removes itself
}
Vielleicht kann's wer brauchen, würde mich freuen!