Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Petra, AndrewAMD, VoroneTZ, 2 invisible), 822 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Error 035 when using CSVtoT6.c #463632
12/18/16 18:21
12/18/16 18:21
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
I want to convert my old .bar files that I downloaded from FXCM to the new .t6 format, so I used the script CSVExport.c to export the history of GBP/USD of 2009. Then, I modified the script CSVtoT6.c to convert that csv to .t6, here is the code, the part that is executed is the one between #ifdef CSVEXPORT ... #endif :

Click to reveal..

Code:
// convert price history from .csv to .t1 or .t6

//#define TRADESTATION
//#define HISTDATA
//#define YAHOO // convert csv data from R or Yahoo
#define CSVEXPORT

#ifdef TRADESTATION
#define TCK T1
string InName = "History\ticks.txt";  // name of the CSV file
string OutName = "History\ticks.t1";
#endif
#ifdef HISTDATA
#define TCK T6
string InName = "History\DAT_ASCII_USDZAR_M1_2015.csv";  // name of the CSV file
string OutName = "History\USDZAR_2015hd.t6";
#endif
#ifdef YAHOO
#define TCK T6
string InName = "History\table.csv";  // name of the CSV file
string OutName = "History\Stock.t6";
#endif
#ifdef CSVEXPORT
#define TCK T6
string InName = "History\GBPJPY.csv"; // name of the CSV file
string OutName = "History\GBPJPY2009.t6";
#endif

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 Dom,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 = Dom;
	Time.wHour = Hour;
	Time.wMinute = Minute;
	Time.wSecond = Second;
	
	DATE vTime;
	SystemTimeToVariantTime(&Time,&vTime);
#ifdef HISTDATA
	vTime += 5./24.; // add 5 hours for converting EST to UTC
#endif
	return vTime;
}

string readTick(string content,TCK* tick)
{
// tokenize a single line	
	char* line = strtok(content,"n");
	if(!line) return 0;

	int Year, Month, Dom, Hour = 0, Minute = 0, Second = 0; 
#ifdef HISTDATA // line format "20100103 170000;1.430100;1.430400;1.430100;1.430400;0"

	if(10 != sscanf(line,"%4d%2d%2d %2d%2d%2d;%f;%f;%f;%f;",
		&Year, &Month, &Dom, &Hour, &Minute, &Second,
		&tick->fOpen, &tick->fHigh, &tick->fLow, &tick->fClose)) 
		return 0;
	tick->fVal = tick->fVol = 0;
#endif
#ifdef YAHOO // line format "2015-05-29,43.45,43.59,42.81,42.94,10901500,42.94"
	float fAdj;

	if(9 != sscanf(line,"%4d-%2d-%2d,%f,%f,%f,%f,%f,%f",
		&Year, &Month, &Dom,
		&tick->fOpen, &tick->fHigh, &tick->fLow, &tick->fClose,&tick->fVol,&fAdj)) 
		return 0;
	if(tick->fClose > 0. && fAdj > 0.) { // adjust for dividends and splits
		float f = fAdj/tick->fClose;
		tick->fOpen *= f;
		tick->fHigh *= f;
		tick->fLow *= f;
		tick->fClose = fAdj;
		tick->fVal = 0;
	}
#endif
#ifdef TRADESTATION // line format "06/30/2016,17:00:00,2086.50,2086.50,2086.50,2086.50,319,0"

	if(7 != sscanf(line,"%2d/%2d/%4d,%2d:%2d:%2d,%f",
		&Month, &Dom, &Year, &Hour, &Minute, &Second,
		&tick->fVal)) 
		return 0;
#endif
#ifdef CSVEXPORT // line format "2009-11-16 14:00, 149.78300, 149.92300, 149.51500, 149.61800"
	if(9 != sscanf(line,"%4d-%2d-%2d %2d:%2d, %f, %f, %f, %f",
		&Year, &Month, &Dom, &Hour, &Minute, &Second,
		&tick->fOpen, &tick->fHigh, &tick->fLow, &tick->fClose)) 
		return 0;
	tick->fVal = tick->fVol = 0;
#endif

// store the time in DATE format
	tick->time = ConvertTime(Year,Month,Dom,Hour,Minute,Second);

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

function main()
{
	if(!file_length(InName)) {
		quit("Data file not found!");
		return;
	}
	string content = file_content(InName);
		
// allocate TICK array		
	int maxticks = strcount(content,0x0a); 
	printf("n%d lines processing...",maxticks);
	int skipped = 0;
	TCK* ticks = malloc(maxticks*sizeof(TCK));

#ifdef HISTDATA
// read ticks in reverse order	
	TCK* tick = ticks+maxticks; 
	while(content)
		content = readTick(content,--tick);

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

#ifdef YAHOO
// skip the header
	content = strstr(content,"n")+1;
// already contains ticks in reverse order	
	TCK* tick = ticks; 
	while(content) {
		content = readTick(content,tick++);
	}
// store the ticks
	int size = (int)(tick-1)-(int)(ticks);
	file_write(OutName,ticks,size);
#endif

#ifdef TRADESTATION
// skip the header
	content = strstr(content,"n")+1;
// read ticks in reverse order	
	TCK* tick = ticks+maxticks;
	while(content) {
		content = readTick(content,--tick);
		if(tick < ticks+maxticks-1) {
			TCK* prev = tick+1;
			if(tick->fVal == prev->fVal) {
				++tick; // skip unchanged quotes
				++skipped;
			} else if(tick->time <= prev->time)
				tick->time += 1./(24.*60.*60.*100.); // add 10 ms
		}	
	}

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

#ifdef CSVEXPORT
// skip the header
	content = strstr(content,"n")+1;
// read ticks in reverse order	
	TCK* tick = ticks+maxticks; 
	while(content)
		content = readTick(content,--tick);

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

	free(ticks);
	printf("n%d ticks written",size/sizeof(TCK));
	if(skipped)
		printf(", %d skipped",skipped);
}




The problem is when I run the script PlotCurve.c I get this in the Zorro console:

PlotCurve compiling...........
Warning 034: No asset data for GBP/JPY
Error 035: Invalid tick time at 30.12.1899
No bars generated
Chart...Error 047: No bars to plot! ok

What is that tick at 30.12.1899 ??

Nevertheless, both PlotCurve (the .bar and .t6 file) looks pretty much the same:

.bar

.t6

Re: Error 035 when using CSVtoT6.c [Re: Mithrandir77] #463645
12/19/16 15:21
12/19/16 15:21
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
30.12.1899 is equivalent to a time stamp of 0. So when you see that date somewhere, something was wrong with the conversion.

Re: Error 035 when using CSVtoT6.c [Re: jcl] #467385
07/30/17 23:12
07/30/17 23:12
Joined: Jul 2017
Posts: 8
A
Alphatecht Offline
Newbie
Alphatecht  Offline
Newbie
A

Joined: Jul 2017
Posts: 8
I got the same problem. I convert csv files into t6 files. When I look at the data inside t6 files using History Editor, I see normal data values with a final data point with timestamp 30.12.1899

What is the main cause for this?
Would ou suggest a direction for solving it?

Re: Error 035 when using CSVtoT6.c [Re: Alphatecht] #467386
07/31/17 05:51
07/31/17 05:51
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
If every timestamp is 0, your date format string is wrong. If it's only the last one, the CSV file probably got blanks in the last line.

Re: Error 035 when using CSVtoT6.c [Re: jcl] #467390
07/31/17 11:02
07/31/17 11:02
Joined: Jul 2017
Posts: 8
A
Alphatecht Offline
Newbie
Alphatecht  Offline
Newbie
A

Joined: Jul 2017
Posts: 8
Thanks a lot


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