A time filter only allows entries during certain windows. You often avoid the first minutes after the open, when spreads are wide and prices unstable, as well as the last minutes before the close.
self.data.datetime.time(0) returns the time of the current bar (a datetime.time object). Example: t = self.data.datetime.time(0), then if t >= datetime.time(9, 30): to enter only from 9:30.
The day matters too: self.data.datetime.date(0).weekday() is 0 on Monday and 4 on Friday. You can close your positions on Friday evening to avoid a price gap at the reopening.
A filter should rest on a market reason: spreads, announcements, liquidity. Testing dozens of windows and keeping the best is overfitting: validate your choice on data you did not use to make it.
Examples
IOTA-X (fictional market) : The golden band marks a risky window, such as the open or an economic announcement. The time filter forbids opening a trade during that moment; the strategy resumes once prices calm down.
24 June 2016: Brexit night : During the night the UK referendum votes were counted, the pound fell from about 1.50 to about 1.32 dollars, its lowest level since 1985. Positions held overnight took the gap in one go, and many stops were filled much further away than planned.
Key terms
Time filter
Rule that limits entries to certain hours
Gap
Jump between one close and the next open
weekday()
Python method giving the day of the week, from 0 (Monday) to 6 (Sunday)
Overfitting
A setting that fits the past by chance and then fails