tock() in Test Mode

Posted By: ozgur

tock() in Test Mode - 12/30/19 14:07

Hi,

I am testing tick() and tock() functions which both work well in Trade Mode. Tick() works in Test Mode as well however I couldn't make tock() work.

According to the manual, tock() should be triggered every bar without TICKS flag.
Quote

In [Test] or [Train] mode or in the lookback period, the tick and tock functions are normally called only once per bar. When the TICKS flag is set, the tick function is called at any new price quote in the historical data.


I modified Workshop4a.c to include tick() and tock() functions.
Logfile shows Tick() functions working but not Tock(). I can't see any errors either. How can I make tock() functional in Test Mode?

Thanks.

Code
// Indicator implementation example //////////////////////////////////
// Formula: Out[0] = (a-a^2/4) * In[0] + a^2/2 * In[1] - (a-3a^2/4) * In[2] + (2-2a) * Out[1] - (1-a)^2 * Out[2]

var lowpass(vars In,int Period)
{
	var a = 1./(1+Period);
	vars Out = series(In[0],3);
	return Out[0] = (a-0.25*a*a)*In[0]
		+ 0.5*a*a*In[1]
		- (a-0.75*a*a)*In[2]
		+ (2-2*a)*Out[1]
		- (1-a)*(1-a)*Out[2];
}

function tick()
{
	if(!is(LOOKBACK))
		print(TO_FILE," This is tick @ %s",datetime());
}

function tock()
{
	if(!is(LOOKBACK))
		print(TO_FILE," This is tock @ %s",datetime());
}

function run() // for testing
{
	set(LOGFILE,PLOTNOW); // ,TICKS
	
	Verbose = 3;
	NumYears = 1;
	
	plot("lowpass",lowpass(series(price()),10),LINE,RED);
}
Posted By: jcl

Re: tock() in Test Mode - 12/31/19 10:03

A tock() function makes probably not much sense in backtesting, since it is time triggered. But it works in test mode, so I can't tell how and why it does not work for you. Maybe you looked in the wrong file or something like that.
Posted By: ozgur

Re: tock() in Test Mode - 12/31/19 14:40

Hi jcl,

I tried couple of things and found a way to make it work: calling asset() in run(). Without asset(), tock() is not triggered in Test Mode. Maybe worth mentioning in the Manual.

I noticed another strange behaviour of tock() in Trade Mode, it only works after a bar close. For example, if BarMode=60 and current time is 14:38 then tock() won't be triggered another 22 minutes(+TockTime). Is this intended?

Thanks
Posted By: jcl

Re: tock() in Test Mode - 01/01/20 17:49

No, that's still not the reason of your problem. tock() has nothing to do with asset() or bar close, so continue testing. Of course, since tock() is time triggered, it depends on ticks, bar periods, and time settings when and how often it is triggered in the backtest.
© 2024 lite-C Forums