FR: make log file name same as Script

Posted By: Zheka

FR: make log file name same as Script - 01/12/22 14:32

When training across assets from a batch file (or just using an asset box to set Asset), one can form Script string in the Init to include an asset name to ensure training writes to different .PAR files.

However, the "_train.log" still has the name of the base script, and so of course parallel processes do not write to the same file. This info gets lost.

Setting LogNumber=strxid(Asset) does not work - strxid() gives the same result for the 'first'/only asset.

Having a switch/case to set the LogNumber is possible but cumbersome. And resulting file names are not really user-friendly.

I see following possible solutions:
- make log file name be the same as Script.
- make LogNumber a string. -> It can then be set to one's desire (e.g. Algo, BarPeriod, Asset, etc)

- automatically make log file name include an asset name - like it is with Brute force optimization.

Posted By: Zheka

Re: FR: make log file name same as Script - 01/12/22 15:45

Related:
If there is no asset() call in the script, Zorro correctly adds asset name to the *.PAR file, *.htm and .png files. (but not to _train.log).

However, if there is:
Code
var bcy_to_usd() {	
	asset(Asset);	
	return 0.1;
}

function run() {	
	set(LOGFILE,PARAMETERS);
	NumYears=2;
		
	if(Init) {
		//sprintf(Script,"AAA%s%s",strmid(Asset,0,3), strmid(Asset,4,3));
		Script="AAA";
			
		watch("Script=",Script);
	}
	
	var Lb = optimize(10, 10, 20,10);
	
	var rate=bcy_to_usd();
	
	LifeTime=Lb;
	
	if (priceC(0)>priceC(Lb)) enterLong();	
	
}
then there is some weird behavior. See screenshot.

Attached picture Script_simple.PNG
Posted By: Petra

Re: FR: make log file name same as Script - 01/13/22 07:55

First select the asset, then optimize.

https://zorro-project.com/manual/en/optimize.htm

https://zorro-project.com/manual/en/errors.htm

By the way, for different logs: LogNumber = 1000*second(wdate(NOW));
Posted By: Zheka

Re: FR: make log file name same as Script - 01/13/22 10:52

Ok, the example above is indeed faulty.

However, if you do this:
Code
var bcy_to_usd() {	
	asset("AUD/USD");	
	return 0.1;
}

function run() {
	
	set(LOGFILE,PARAMETERS);
	NumYears=2;
			
	asset(AssetBox);
	
	sprintf(Script,"AAA%s%s",strmid(Asset,0,3), strmid(Asset,4,3));
		
	var Lb = optimize(10, 10, 20,10);	
	
	var rate=bcy_to_usd();
	
	LifeTime=Lb;	
	if (priceC(0)>priceC(Lb)) enterLong();		
}
then the log file (and the .htm) get no extension.

And the original issue/ motivation for FR still hold: only the most recent optimization run gets written to the log file - which is a problem when optimizing many assets from a .BAT file.

Edit: just saw your last suggestion on LogNumber. This is workable, but user-unfriendly..go figure which file belongs to which asset... Why can't the log file name be the same as Script?
Posted By: Petra

Re: FR: make log file name same as Script - 01/14/22 11:49

https://manual.zorro-project.com/str_.htm

sprintf (string dest, string format, ...): int
Like strf, but fills a given char array with formatted data, and returns the number of characters written. The dest char array must have sufficient size. Parameters:
dest - destination string, a char array of sufficient length.
format - format string (see format codes).


static char Name[100];
sprintf(Name,.....);
Script = Name;
Posted By: Zheka

Re: FR: make log file name same as Script - 01/14/22 13:31

You are right, sprintf() requires a char[], thank you...I usually use strf() which worked correctly.

Still, having a log file have the same name as .par file would be quite convenient. (with the LogNumber =second() with the BAT file still some files get the same name, requiring to add timeouts....so much dancing around such a trivial issue).
Posted By: jcl

Re: FR: make log file name same as Script - 01/14/22 13:42

The log file cannot have the same name as the .par file because you normally want different scripts to share the same parameter files. Like Z1, Z2, Z12.

Besides, you can easily do that by script. Use LogNumber to store different log files, and when you want individual names, just file_copy it at the end of the session.
Posted By: Zheka

Re: FR: make log file name same as Script - 01/14/22 18:57

Different scripts sharing the same parameter files is a rare exception needed for 'publishing'/end-using Z-systems. Bulk of the work is spent in development where convenience and efficiency are key.

Besides, what's the problem with scripts 'xxxxx.c' and 'zzzzz.c' both setting Script='yyyyy' to read 'yyyyy.par' in Live/Test but writing to 'yyyyy_train.log" in Train?
© 2024 lite-C Forums