Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Codeschnipsel (http://www.expert-advisor.com/forum/forumdisplay.php?f=292)
-   -   Binärdateien lesen (http://www.expert-advisor.com/forum/showthread.php?t=5596)

Kronenchakra 05.04.17 23:40

Binärdateien lesen
 
Der einzige Nachtei der Binärdateien, man kann sie mit einem Texteditor nicht lesen.
Dazu ist ein Hexeditor notwendig oder ein dafür vorgesehenes Programm.
Hier ist das Gegenstück zu Binärdateien schreiben.
Dieses läuft ebenfalls sowohl im MT5 als auch im MT4.
Es ist diesmal als Script programmiert.
Code:

//+------------------------------------------------------------------+
//|                                            FileReadTicksBin.mq5 |
//|                                Copyright © 2017 Ing. Otto Pauser |
//+------------------------------------------------------------------+
#property copyright  "Copyright © 2017 Ing. Otto Pauser"
#property version    "1.00"
#property description "Dieses Script liest die Tickdaten von FileWriteTicksBin"
#property description "und läuft sowohl im MT5 als auch im MT4!"
#property description "Der Symbolname wir automatisch dem Dateinamen vorgestellt.\n"
#property description "Press <ESC> to stop reading tickdata or wait till finished"
#property script_show_inputs

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

string  fn = fPath+"\\"+_Symbol+"_"+fName;    // full filename
int      fh,                                    // file handle
        ff = FILE_READ|FILE_BIN;              // file flags
bool    ok = true;                            // _StopFlag is not customizeable so we create our own flag
       
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       

//+------------------------------------------------------------------+
void OnStart()
{
  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* file "+fn+" not found.");
  else
      ReadFile();                  // read the file

  FileClose(fh);                  // close the file
 
  PlaySound("ok");                // make some noise
}

//+------------------------------------------------------------------+
void ReadFile()
{
  Comment("Reading tickdata from file: "+fn);  // information
  while(!FileIsEnding(fh) && ok)
      {
        FileReadStruct(fh,tick);              // read the line
        Print(tick.Time," ",DoubleToString(tick.Ask,_Digits)," ",DoubleToString(tick.Bid,_Digits)," ",tick.Spread);
      }
  Comment("");                                // clear information
}

//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
  if(id==CHARTEVENT_KEYDOWN)                  // key pressed ?
      if(lparam==27)                            // <ESC> ?
        ok=false;                              // set our stopflag
}

Ich habe mich früher beruflich mit AutoCAD beschäftigt, und Dateikonvertierungen gehörten zum Alltag.
Plottfiles analysieren und umwandeln, damit diverse Drucker oder Plotter das verdauen konnten, Koordinaten transformieren, etc.

Ich denke man kann das auch recht gut für Kursdaten verwenden.

Grüße Otto


Alle Zeitangaben in WEZ +2. Es ist jetzt 04:38 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum