Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (ozgur, TipmyPip), 722 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ConvertTime & Convert.c? #440384
04/24/14 18:33
04/24/14 18:33
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
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.

Re: ConvertTime & Convert.c? [Re: DdlV] #440417
04/25/14 11:53
04/25/14 11:53
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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));
}


Re: ConvertTime & Convert.c? [Re: jcl] #440427
04/25/14 12:40
04/25/14 12:40
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
Thanks!

Re: ConvertTime & Convert.c? [Re: DdlV] #441910
06/06/14 02:26
06/06/14 02:26
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline
Newbie
hermit2795  Offline
Newbie
H

Joined: Mar 2014
Posts: 9
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 Files
EURUSD_M1.zip (2 downloads)
Re: ConvertTime & Convert.c? [Re: hermit2795] #441911
06/06/14 09:53
06/06/14 09:53
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Re: ConvertTime & Convert.c? [Re: jcl] #441915
06/06/14 11:38
06/06/14 11:38
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline
Newbie
hermit2795  Offline
Newbie
H

Joined: Mar 2014
Posts: 9
thanks jcl. now it works for me.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1