void ImportBarFile(JForex_Data_Files file)
{
StreamReader streamReader = new StreamReader(file.FilePath);
StreamWriter streamWriter = new StreamWriter(file.FileTargetPath);
string dateFormat;
dateFormat = "yyyy.MM.dd HH:mm:ss";
char fieldSplitter = ',';
IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
string line = "";
int bars = 0;
try
{
while (!streamReader.EndOfStream)
{
line = streamReader.ReadLine();
if (line.StartsWith("Time"))
continue; // Skips annotation line.
string[] data = line.Split(new char[] { fieldSplitter });
DateTime time = DateTime.ParseExact(data[0], dateFormat, formatProvider);
double open = StringToDouble(data[1]);
double high = StringToDouble(data[2]);
double low = StringToDouble(data[3]);
double close = StringToDouble(data[4]);
int volume = (int)StringToDouble(data[5]);
if (volume > 0 && !(open == high && open == low && open == close))
{
streamWriter.WriteLine(
time.ToString("yyyy-MM-dd\tHH:mm") + "\t" +
open.ToString() + "\t" +
high.ToString() + "\t" +
low.ToString() + "\t" +
close.ToString() + "\t" +
volume.ToString()
);
bars++;
}
}
}
catch (Exception excaption)
{
MessageBox.Show(excaption.Message);
}
streamWriter.Close();
streamReader.Close();
SetInfoText(file.Symbol + " " + Data.DataPeriodToString((DataPeriods)file.Period) + " - " +
(Language.T("Bars")).ToLower() + ": " + bars.ToString() + Environment.NewLine);
}