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