Hello all,
after Dusktrader's excellent trading script, I wa eager to create some other strategy's. Come to find out, I don't have access to the history that I need from my trading account with Finfx. I don't have a fxcm account so I went to histdata and downloaded a sample of their data.
the data is formatted as follows:
Row Fields:
DateTime Stamp,Bid Quote,Ask Quote,Volume

DateTime Stamp Format:
YYYYMMDD HHMMSSNNN

Legend:
YYYY – Year
MM – Month (01 to 12)
DD – Day of the Month
HH – Hour of the day (in 24h format)
MM – Minute
SS – Second

I've attached my script which doesn't seem to be able to move the open,close,high and low to the TICK structure and doesn't seem to create the .bar file. It also aborts after the third time thru.
I'm out of ideas. Would appreciate any help any one can bring.
Thanks
P

//convert History downloaded from www.histdata.com
//download each year, change in excel to use a comma delimited file, if not already
//sorted so the latest entry in first as required by zorro.
//This script will read the file defined in the script, convert the records to Zorro's
//format and then write them to a binary file name export.bar to be used by Zorro.
//youo can then rename the file to the Zorro .bar format.
//the format of the histdata.com file is DateTime,Open,High,Low,Close,Volume
//the format for zorron is the tick stru included in include\trading.h
//including OLE Date.counting days since midnight 30 December 1899
//typedef struct TICK{ float fOpen, fClose; float fHigh, fLow; DATE time; // time of the tick in UTC time, OLE date/time format} TICK;
//
//the timezone for the histdata.com files is EST without daylight savings time
//so the conversion must take that into account
#include <default.c>
//#include <litec.h>
#include <stdio.h>
#include <trading.h>

TICK mytick;
int count=0;

typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;

API(SystemTimeToVariantTime,oleaut32)
int _stdcall SystemTimeToVariantTime(SYSTEMTIME* lpSystemTime, double* pvtime);

DATE ConvertTime(int Year,int Month,int Day,int Hour,int Minute)
{
SYSTEMTIME Time;
memset(&Time,0,sizeof(SYSTEMTIME));
Time.wYear = Year;
Time.wMonth = Month;
Time.wDay = Day;
Time.wHour = Hour;
Time.wMinute = Minute;
DATE vTime;
SystemTimeToVariantTime(&Time,&vTime);
return vTime;
}

function convertdata(string csv)
{
string nextline = strstr(csv,"\n");//this is the file without the first line
string separator = ",";

int Year,Month,Day,Hour,Minute;
int mysec;
//use the csv string to seperate the date time
//format of datetime is "YYYYMMDD HHMMSS" SS is always zero and is not used
sscanf(strtok(csv,separator),"%4i%2i%2i %2i%2i%2i",&Year,&Month,&Day,&Hour,&Minute,&mysec);
mytick.time = ConvertTime(Year,Month,Day,Hour,Minute);

//separate the other vars last column is vol it is always 0 and is ignored
sscanf(strtok(0,separator),"%f",&mytick.fOpen);
sscanf(strtok(0,separator),"%f",&mytick.fHigh);
sscanf(strtok(0,separator),"%f",&mytick.fLow);
sscanf(strtok(0,separator),"%f",&mytick.fClose);
printf("\n %f %f %f %f %f",mytick.time,mytick.fOpen,mytick.fHigh,mytick.fLow,mytick.fClose);

return nextline;
}

function main()
{
string Name = "History\\AUDCAD_M1_2012.csv"; // name of the CSV file containing M1 data
if(!file_date(Name)){
quit("File not found!");
}
//open and create export.bar
FILE* pfile;
pfile=fopen("export.bar","w+b");
if(pfile==NULL){
quit("\n unable to open bar file");
}

printf("\n%s found export file opened",Name);
string mycontent = file_content(Name);
printf("\n firstline %s",mycontent);
while(mycontent) {
mycontent=convertdata(mycontent);
printf("\n nextline %s", mycontent);
fwrite(&mytick,sizeof(mytick),sizeof(mytick),pfile);
if(ferror(pfile)){
printf("\nfile write error");
}
x++;
}//endwhile
printf("\n before close file");
fclose(pfile);
}

Last edited by Pork; 01/03/14 14:17.