EURUSD1440.hst convet to EURUSD1440.txt// Delphi Source

 
EURUSD1440.hst convet to EURUSD1440.txt// Delphi Source

program Project1;

uses
SysUtils, Classes;

type
PBarMeta = ^TBarMeta;
TBarMeta = packed record
_date_time: Integer;
_open: Double;
_low: Double;
_high: Double;
_close: Double;
_volume: Integer;
end;

TListBars = class(TList)
public
procedure Clear; override;
end;

const
file_header_pos = 144;
time_min_off = 0.000694444446708076; //= 1 minuta
begin_date_time = 25569.0833333333; //MetaTrader - 7260 = 1970.01.01 02:00

var
_Chart_List: TListBars;

{ TListBars }

procedure TListBars.Clear;
var
i: Integer;
begin
for i := 0 to Count - 1 do Dispose(Items[i]);
inherited;
end;

procedure SaveToText_Omega(txtFile: string);
var
S: string;
n: Integer;
bar: TBarMeta;
ChartList: TStringList;
_date: TDateTime;
begin
ChartList := TStringList.Create;
try
ChartList.Add('<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>');
for n := 0 to _Chart_List.Count - 1 do
begin
bar := PBarMeta(_Chart_List.Items[n])^;
with bar do
begin
_date := (begin_date_time + ((_date_time - 7200)/60) * time_min_off);

S := FormatDateTime('yyyymmdd', _date);
S := S + ',' +
FormatFloat('0.###0', _open) + ',' +
FormatFloat('0.###0', _high) + ',' +
FormatFloat('0.###0', _low) + ',' +
FormatFloat('0.###0', _close) + ',' +
IntToStr(_volume);
if (_open > 0.0001) and (_high > 0.0001) and
(_low > 0.0001) and (_close > 0.0001) then ChartList.Add(S);
end;
end;
ChartList.SaveToFile(txtFile);
finally
ChartList.Free;
end;
end;

function DecodeBarExt(hstFile: string): Boolean;
var
_file: TFileStream;
PBar: PBarMeta;
begin
_file := TFileStream.Create(hstFile, fmOpenRead);
try
_file.Position := file_header_pos;
while _file.Position < _file.size do
begin
New(PBar);
fillchar(PBar^, sizeof(TBarMeta), 0);
if _file.Read(PBar^, sizeof(TBarMeta)) > 0 then
_Chart_List.Add(PBar);
end;
Result := True;
finally
_file.Free;
end;
end;

begin
_Chart_List := TListBars.Create;
try
if DecodeBarExt('C:\Program Files\MetaTrader\bases\EURUSD1440.hst') then
SaveToText_Omega('c:\EURUSD1440.txt');
finally
_Chart_List.Free;
end;
end.