I have an algo with the following definition of opening times:
Ctime = time >=080000 and time <163000
the entry conditions are:
if Ctime and not onmarket or longonmarket and cb1 and cb2 and barindex-tradeindex(1)>=LookbackPeriod then
BUY positionsize CONTRACTS AT highest[LookbackPeriod](high)+PointsDistance*pointsize STOP
SET STOP pLOSS sl
SET TARGET %PROFIT tp
endif
if Ctime and not onmarket or shortonmarket and cs1 and cs2 and barindex-tradeindex(1)>=LookbackPeriod then
SELLSHORT positionsize CONTRACTS AT lowest[LookbackPeriod](low)-PointsDistance*pointsize STOP
SET STOP pLOSS sl
SET TARGET %PROFIT tps
endif
but I find it is placing orders outside of the Ctime definition.
I presume this is due to the system placing Stop Orders – and if this is the case, is there any way to restrict a stop order to only work within that time definition?
The issue is in the icorrect placing of parentheses, try this:
if Ctime and (not onmarket or longonmarket) and cb1 and cb2 and ((barindex-tradeindex(1))>=LookbackPeriod) then
if Ctime and (not onmarket or shortonmarket) and cs1 and cs2 and ((barindex-tradeindex(1))>=LookbackPeriod) then
thanks Roberto, I’ll try that.
Hmm, one small problem – this completely destroys the performance. It goes from being highly successful to total disaster.
Is the way I originally had it seriously wrong? ie, giving false results?
No, it only enters outside your time range. If this is good for you, then it’s fine.
Bear in mind that outside that time range spreads may be higher (and rquired distances from price as well). This might impact peformance.
outside that time range spreads may be higher
Yes, this was the main problem. It works with a tiny stop loss of just 5 points, but overnight the DAX minimum goes up to 10 so orders get cancelled and then the system gets stopped.
But now I realize there’s a bigger problem: the way i originally had it doesn’t work anymore either. Last week it was fine, showing massive profit over 10 years, now it breaks the bank almost immediately – exact same code, unchanged. Unfortunately I didn’t keep a print of the results I was getting.
So the disaster is not due to the changes you suggested, but some weirdness in the PRT backtests.
I’ve attached the itf if anyone wants to make further tests because i have no idea what is going on here.
On DAX, 1-hour TF (200K bars), 2-pip spread, it’s not that bad! (it worked similarly on the 30-minute and 15-minute TF).
I used my modifications and reaplaced TIME with OPENTIME.
Bear in mind that 8-16:30 is a bit different for me, it’s 7-15:30 UK.
This is making my head spin – suddenly it tests ok again, with absolutely no changes! (v4)
Also with your change to the ( ) now works. The profit drops as expected due to the time limit, but still acceptable. (v5T)
Molto misterioso …
It must be mood dependent! 😂