Timing
Timing fields and functions enable time‑aware rules in your strategies. They help you select specific trading windows (e.g., first trading days of a month), measure days in a period, and anchor calculations to market events. You’ll use these with Entry, Adjustment, Exit).
Timing variables are decimals; for casting and tolerant comparisons, see v2 to v3 Migration → Timing variables are now decimals.
Practical example
Consider you would like to enter a position during the turn of the month and hold it one day before the OPEX cycle.
This can be achieved by using the timing module as follows:
"Entry": {
...
"Conditions": [
"timing.trading_days_until(next_month, first) <= 1 -- Entry on the last day of the month"
],
"VarDefines": {
"minutes_after_open": "timing.minutes_after_open"
}
},
"Exit": {
"Conditions": [
"timing.trading_days_until(monthly_opex) < 2 -- Exit one day before OPEX"
],
"VarDefines": {
"days_in_trade": "timing.days_in_trade -- capture exact days in trade"
}
},
...
The above example is demonstrated in the [FEAT-TimingModule] built-in template.
Prototypes
Variables
| Name | Type | Description |
|---|---|---|
timing.day_of_week | int | 0=Sunday … 6=Saturday |
timing.year | int | Current year in exchange time |
timing.month | int | Current month (1–12) in exchange time |
timing.day | int | Current day of month in exchange time |
timing.minutes_after_open | int | Minutes since market open (5‑minute resolution) |
timing.minutes_before_close | int | Minutes until market close (5‑minute resolution) |
timing.days_in_trade | decimal | Decimal days since position entry time |
Functions
| Signature | Description |
|---|---|
timing.trading_days_until(anchor, [boundary]) -> decimal | Trading days from now until anchor (optional boundary) |
timing.trading_days_after(anchor, [boundary]) -> decimal | Trading days after anchor up to boundary (optional) |
timing.calendar_days_until(anchor, [boundary]) -> decimal | Calendar days from now until anchor (optional boundary) |
timing.calendar_days_after(anchor, [boundary]) -> decimal | Calendar days after anchor up to boundary (optional) |
timing.trading_days_in(anchorA, [anchorB], [a_boundary], [b_boundary]) -> decimal | Trading‑day count within a window |
timing.calendar_days_in(anchorA, [anchorB], [a_boundary], [b_boundary]) -> decimal | Calendar‑day count within a window |
Anchors & Boundaries
| Name | Description |
|---|---|
this_week | Current trading week anchor |
next_week | Next trading week anchor |
last_week | Previous trading week anchor |
this_month | Current calendar month anchor |
next_month | Next calendar month anchor |
last_month | Previous calendar month anchor |
this_quarter | Current calendar quarter anchor |
next_quarter | Next calendar quarter anchor |
last_quarter | Previous calendar quarter anchor |
this_year | Current calendar year anchor |
next_year | Next calendar year anchor |
last_year | Previous calendar year anchor |
monthly_opex | Monthly options expiration (3rd Friday for standard index/equity options) |
vix_settlement | VIX settlement event anchor |
triple_witching | Triple witching event anchor |
quad_witching | Quadruple witching event anchor |
first | Start boundary of the selected period/window |
last | End boundary of the selected period/window |
Usage Notes
- Anchors can be used standalone (e.g.,
timing.trading_days_until(this_month)), or paired with boundaries to constrain windows. - Combine timing variables/functions with Entry/Adjustment/Exit schedules to refine when conditions are checked.