ConvertTime & Convert.c?

Posted By: DdlV

ConvertTime & Convert.c? - 04/24/14 18:33

Hi jcl. I'm attempting to convert some downloaded History from csv to bar. I can't seem to locate ConvertTime and Convert.c. Where do I find them in 1.22.2?

Thanks.
Posted By: jcl

Re: ConvertTime & Convert.c? - 04/25/14 11:53

Convert.c was indeed missing, here is it:

Code:
string InName = "Data\\DAT_ASCII_EURUSD_M1_2013.csv";  // name of the CSV file
string OutName = "History\\EURUSD_2013x.bar";

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,int Second)
{
	SYSTEMTIME Time;
	memset(&Time,0,sizeof(SYSTEMTIME));
	if(Year < 50) Year += 2000;
	else if(Year < 100) year += 1900;
	Time.wYear = Year;
	Time.wMonth = Month;
	Time.wDay = Day;
	Time.wHour = Hour;
	Time.wMinute = Minute;
	Time.wSecond = Second;
	
	DATE vTime;
	SystemTimeToVariantTime(&Time,&vTime);	
	return vTime;
}

string readTick(string content,TICK* tick)
{
// tokenize a single line	
	char* line = strtok(content,"\n");
	if(!line) return 0;
	
// read "20100103 170000;1.430100;1.430400;1.430100;1.430400;0"
	int Year, Month, Day, Hour, Minute, Second; 

	if(10 != sscanf(line,"%4d%2d%2d %2d%2d%2d;%f;%f;%f;%f;",
		&Year, &Month, &Day, &Hour, &Minute, &Second,
		&tick->fOpen, &tick->fHigh, &tick->fLow, &tick->fClose)) 
		return 0;
		
// store the time in DATE format
	tick->time = ConvertTime(Year,Month,Day,Hour,Minute,Second);

// return pointer to next line
	return line+strlen(line)+1;
}

function main()
{
	if(!file_length(InName))
		quit("Data file not found!");
		
// allocate TICK array		
	int maxticks = 60*24*365; 
	TICK* ticks = malloc(maxticks*sizeof(TICK)),
		tick = ticks+maxticks; 

// read ticks in reverse order	
	string content = file_content(InName);
	while(content) 
		content = readTick(content,--tick);

// store the ticks
	int size = (int)(ticks+maxticks)-(int)(tick+1);
	file_write(OutName,tick+1,size);
	free(ticks);

	printf("\nRead %d ticks",size/sizeof(TICK));
}

Posted By: DdlV

Re: ConvertTime & Convert.c? - 04/25/14 12:40

Thanks!
Posted By: hermit2795

Re: ConvertTime & Convert.c? - 06/06/14 02:26

I came across a program that will download tick data from ducascopy here... http://www.strategyquant.com/tickdatadownloader/

and it will output it to a M1 csv file... attached

I am trying to use the convert script but am having trouble with this. I'm not sure how to change the script so that it will read the csv file (I've tried). any help appreciated

Attached File
EURUSD_M1.zip  (2 downloads)
Posted By: jcl

Re: ConvertTime & Convert.c? - 06/06/14 09:53

This file uses a different date/time format. So you must change the first part of the sscanf(line... function for retrieving the date and time.

Instead of

"%4d%2d%2d %2d%2d%2d;"

it looks like

"%4d.%2d.%2d,%2d:%2d,"

Also, your file has no seconds, and the separator is a comma, not a semicolon.
Posted By: hermit2795

Re: ConvertTime & Convert.c? - 06/06/14 11:38

thanks jcl. now it works for me.
© 2024 lite-C Forums