Backtest with specific entry time

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
raven
Posts: 31
Joined: 17 Oct 2009
Been thanked: 1 time

Backtest with specific entry time

Postby raven » 09 Nov 2009

I would like to backtest an intraday system that allows no entries no later then 11 a.m.

The trigger signals are based on 1 day charts. Intrabar order generation as solution doesn't work. Meanwhile I tried to utilize a second data stream (data2) but with no success.

Does anybody know how to proceed? (For realtime trading it should be easy: "currenttime < 1100". But this and other functions don't work for backtesting.)

Many thanks in advance.

raven
Posts: 31
Joined: 17 Oct 2009
Been thanked: 1 time

data2

Postby raven » 09 Nov 2009

Tried to reference data2 with functions like "barstatus", "entrytime", "lastcalcmmtime" or "sess1firstbartime".

data1 is 1 day bar, data 2 is 3 hour bar, session time is 08.00 a.m. to 6 p.m.

Whenever adding one of these functions to the code it's always the same: either no entries at all or entries as I hadn't added any additional function.

Simplified code example (applied to data1; 1 day bar):

condition1 = High > Low + 20;
if condition1 then buy 1 contract next bar at Open next bar;

So, how to reference data2 and what length of bar (1h, 3h, ...?) is appropriate to produce daily entries no later then 11.00 a.m. (sessions as above mentioned from 08.00 a.m. to 6 p.m.)?

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Postby TJ » 09 Nov 2009

try this

var:
time2(0);

time2 = time data2;

if time2 <= 1100 then
begin

{... your trading instructions here}

end;



data2 is for the time trigger only,
therefore any intraday time frame that has a 1100 break should be ok.

raven
Posts: 31
Joined: 17 Oct 2009
Been thanked: 1 time

Postby raven » 10 Nov 2009

Thank you, but didn't produce any entries. Reason might be that the entry related data1 can't use information about timestamps of data2 if - as I described above - data1 timeframe for a bar is greater then that of data2. Conversely it works (without your hint but completing the code a little bit):

condition1 = High data2 > Low data2 + 20 and time next bar = 1100;
if condition1 then buy 1 contract next bar at Open next bar;

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Postby TJ » 10 Nov 2009

you have 2 issues here:

1. stop the trade after certain time
2. order triggering logic


your original question is on #1 issue.

I have not looked at your second issue.

you should separate the issues and tackle them separately.


Return to “User Contributed Studies and Indicator Library”