Short trades not being taken

Posted By: swingtraderkk

Short trades not being taken - 08/26/13 19:30

OK spent way too long trying to bug hunt this issue. For some reason, long trades only are being taken my scripts.

Example script below:

Code:
function run()
{
	set(LOGFILE);
	BarOffset = timeOffset(ET,0,17,0);
	BarPeriod = 1440;
	StartDate = 2002;	
	
	vars cl	= series(priceClose());
	int threshold = 80;
	int exitbars  = 8;
	
	ExitTime = exitbars;
	Stop = 140*PIP;
	
	if (cl[0] > MaxVal(cl+1,threshold)) enterLong();
	if (cl[0] < MinVal(cl+1,threshold))	enterShort();
}

Posted By: Anonymous

Re: Short trades not being taken - 08/26/13 20:59

Add LookBack = 100 (for example), then it works.

Although it is a bit strange that M{ax,in}Val functions don't complain about Lookback, but many others do. Probably that fact confused you.
Posted By: swingtraderkk

Re: Short trades not being taken - 08/27/13 04:51

Thanks acidburn!

This was driving me crazy!

Especially because MaxVal seemed to cope just fine without LookBack.

Another strange issue is why a LookBack of 80 doesn't work.

BTW does this code successfully use daily bars with a daily close of 5pm ET?
Posted By: jcl

Re: Short trades not being taken - 08/27/13 08:24

No, for daily bars starting and closing at 17:00 ET, you need this:

BarOffset = (ET+17)*60;

And the short trade problem was indeed tricky, I had to look twice until I saw the reason. You're shifting the series by 1 and use 80 bars, so your lookback period must be 1+80 = 81 at least. The default is 80.

The too short lookback period caused the first value of the series to be wrong, therefore the short trade condition was never met. The computer can not detect this kind of error, so you get no error message.
Posted By: swingtraderkk

Re: Short trades not being taken - 08/27/13 16:51

Thanks jcl.

Much appreciated on both counts.
© 2024 lite-C Forums