4 registered members (M_D, AndrewAMD, Quad, Ayumi),
806
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Question on bar generation, why the "extra" bar?
#469192
11/07/17 19:42
11/07/17 19:42
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2017
Posts: 369
|
I have some M1 data for an asset that is open 0800 to 1645. (some days actually only have data from 0802 or so, as we can see below) Given that the M1 data ends at 1645 (market close), I was a bit surprised to see bars generated for the 2000 hour, since the market is not open by then. A simple script like this
function run()
{
set(LOGFILE+PARAMETERS);
StartDate = 20170801;
EndDate = 2017;
LookBack = 600;
BarPeriod = 240;
StartWeek = 10800;
EndWeek = 51645;
vars prices = series(priceClose());
LifeTime = 10;
if (prices[0] > ATR(200))
enterLong();
}
This generates a testlog that looks something like this:
[664: Mon 16-10-24 08:00] (10698.20)
[665: Mon 16-10-24 12:00] (10743.87)
[666: Mon 16-10-24 16:00] (10793.82)
[667: Mon 16-10-24 20:00] (10778.14)
[668: Tue 16-10-25 12:00] (10786.25)
[669: Tue 16-10-25 16:00] (10791.68)
[670: Tue 16-10-25 20:00] (10762.88)
[671: Wed 16-10-26 12:00] (10726.22)
[672: Wed 16-10-26 16:00] (10647.86)
[673: Wed 16-10-26 20:00] (10701.58)
[674: Thu 16-10-27 12:00] (10691.86)
[675: Thu 16-10-27 16:00] (10699.20)
[676: Thu 16-10-27 20:00] (10677.64)
[677: Fri 16-10-28 12:00] (10634.99)
[678: Fri 16-10-28 16:00] (10687.86)
Every day ends with a bar at 20:00, except Friday (since I set EndWeek to 51746). I also get entries like this
[1421: Tue 11-03-15 16:00] -14053 +313 19/22 (6561.38)
[1422: Tue 11-03-15 20:00] -14053 +799 19/22 (6597.55)
[TEST:9:L2201] Long 1@6643.94 Risk 3103$ p at 20:00:00
Here a position is entered at 20:00. But like I said, the marked closed at 16:45, so in live trading this trade couldn't possibly happen. This is just one example, I get positions both opened and closed at 20:00. Is this a bug, or am I missing something here? It just seems strange to me that a backtest can open/close trades when there is no historic data for the underlying asset.
|
|
|
Re: Question on bar generation, why the "extra" bar?
[Re: jcl]
#469223
11/08/17 19:21
11/08/17 19:21
|
Joined: Jul 2017
Posts: 784
Zheka
User
|
User
Joined: Jul 2017
Posts: 784
|
So, in this case, to achieve a situation when the first 240min *period* in a day starts at 8:00 and the last ends at 16:45, one would do as follows: ........... BarPeriod=15; FrameOffset=8; TimeFrame= framesync(24); TimeFrame=16; //15*16=240 price=..... if hour()=1600 and minute()=45 { TimeFrame=0} enterLong() ....................
Correct?
Last edited by Zheka; 11/08/17 19:22.
|
|
|
Re: Question on bar generation, why the "extra" bar?
[Re: jcl]
#469913
12/13/17 11:52
12/13/17 11:52
|
Joined: Jul 2017
Posts: 784
Zheka
User
|
User
Joined: Jul 2017
Posts: 784
|
JCL, I discovered that TimeFrame=AssetFrame works only in whole hours. E.g.: BarPeriod=20; AssetZone=ET; FrameOffset=51; //51=17hrs of 3x 20min bars; TimeFrame=AssetFrame; will end the Daily bar at 17:00 ET. But with FrameOffset=50 (i.e. 1 bar less), the daily bar will end at 16:00 ET, not 16:40. Can this be behaviour be changed to the expected?
|
|
|
|