FRENESDE

Time-of-day filters

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

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
Take the mission on Doji Academy

← Back to the index