Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 403 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Script2015 Trend.c Line 33 Error #464466
02/15/17 23:36
02/15/17 23:36
Joined: Feb 2017
Posts: 1
T
til Offline OP
Guest
til  Offline OP
Guest
T

Joined: Feb 2017
Posts: 1
Hi,

I wasn't able to find anything related to Tutorials from FinancialHacker Script2015 and got an error I'm not able to overcome.

The error where I don't C enough resides in Trend.c - code below Error Msg.

Do you have an idea how to fix it?

Thanks!

TrendALMA compiling.......
Error in 'trend.c' line 33:
Redefined with different type: g
< int Day = 0;
>
Error in 'trend.c' line 33:
syntax error
< int Day = 0;
>.
Copied to Clipboard!

Code:
// Trend Trading Experiment ///////////////////
#include <default.c>

//#define WRC
//#define DO_STATISTIC

#ifdef DO_STATISTIC	
var _getvar(string filename,string name)
{
	if(!file_date(filename)) return 0;
	return strvar(file_content(filename),name,0);
}

void _putvar(string filename,string name,var value)
{
	string line = strf("%s %12.5fn",name,value);
	string s = 0,content = 0;
	if(file_date(filename)) 
		content = file_content(filename);
	if(content)
		s = strstr(content,name);
	if(!s)
		file_append(filename,line);
	else {
		memcpy(s,line,strlen(line));
		file_write(filename,content,0);
	}
}
#endif

int Period;
var Daily[3000];
int Day = 0;

var objective() 
{ 
	if(NumWinTotal < 30 || NumLossTotal < 30) { // not enough trades
		g->bDoStep = 0;	// abort optimization
		return 0; 
	}
	
#ifdef DO_STATISTIC	
// store the result statistic	
	string FileName = "LogTrendStats.txt";
	string NameScript,NameAsset,NameAlgo;
	if(WinTotal > LossTotal) {
		NameScript = strf("%s_Won",Script);
		NameAsset = strf("%s_Won",Asset);
		NameAlgo = strf("%s_Won",Algo);
	} else {
		NameScript = strf("%s_Lost",Script);
		NameAsset = strf("%s_Lost",Asset);
		NameAlgo = strf("%s_Lost",Algo);
	}
	lock();
	var Score = _getvar(FileName,NameScript);
	_putvar(FileName,NameScript,Score+1);
	Score = _getvar(FileName,NameAsset);
	_putvar(FileName,NameAsset,Score+1);
	Score = _getvar(FileName,NameAlgo);
	_putvar(FileName,NameAlgo,Score+1);
	unlock();
#endif	

#ifdef WRC
// store the curves of daily returns
	string FileName = "LogTrendDaily.bin";
	string Name = strf("%s_%s_%s_%i",Script,Asset,Algo,Period);
	int Size = Day*sizeof(var);
	lock();
	file_append(FileName,Name,strlen(Name)+1);
	file_append(FileName,&Size,sizeof(int));
	file_append(FileName,Daily,Size);
	unlock();
#endif
	
	return WinTotal/max(1,LossTotal); // Profit factor
}

var filter(var* Data,int Period);

void run()
{
	set(PARAMETERS|LOGFILE);
	PlotHeight1 = 200;
	PlotScale = 8;
	ColorBars[1] = BLACK; // winning trades
	ColorBars[2] = GREY; // losing trades

#ifdef WRC
	Spread = Commission = RollLong = RollShort = Slippage = 0;
#endif

	StartDate = 2010;
	BarPeriod = 15;
	LookBack = 80*4*24; // ~ 4 months
	
	while(asset(loop("EUR/USD","SPX500","XAG/USD")))
	while(algo(loop("M15","H1","H4")))
	{
		TimeFrame = 1;
		if(Algo == "H1")
			TimeFrame = 4;
		else if(Algo == "H4")
			TimeFrame = 4*4;	

		int Periods[10] = { 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000 };
		Period = Periods[optimize(1,1,10,1)-1];
		
		var *Price = series(price());
		var *Smoothed = series(filter(Price,Period));

		if(valley(Smoothed))
			enterLong();
		else if(peak(Smoothed))
			enterShort();
	} 
	
#ifdef WRC
// story daily result
	static int LastDay = 0;
	if(is(LOOKBACK))
		LastDay = Day = 0;
	else if(LastDay != day()) {
		Daily[Day++] = Balance;
		LastDay = day();
	}
#endif
}



ps

One error I was able to solve is, that Script 2015>TrendXYZ expects Trend.c to be located in ...Script, not in ...Script/Trend

Last edited by til; 02/15/17 23:39.
Re: Script2015 Trend.c Line 33 Error [Re: til] #464502
02/20/17 10:30
02/20/17 10:30
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Change "Day" to a different name. Unlike in 2015, the newer Zorros have an internal variable named "Day".


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