Skip to main content

Timing

New in v3

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

NameTypeDescription
timing.day_of_weekint0=Sunday … 6=Saturday
timing.yearintCurrent year in exchange time
timing.monthintCurrent month (1–12) in exchange time
timing.dayintCurrent day of month in exchange time
timing.minutes_after_openintMinutes since market open (5‑minute resolution)
timing.minutes_before_closeintMinutes until market close (5‑minute resolution)
timing.days_in_tradedecimalDecimal days since position entry time

Functions

SignatureDescription
timing.trading_days_until(anchor, [boundary]) -> decimalTrading days from now until anchor (optional boundary)
timing.trading_days_after(anchor, [boundary]) -> decimalTrading days after anchor up to boundary (optional)
timing.calendar_days_until(anchor, [boundary]) -> decimalCalendar days from now until anchor (optional boundary)
timing.calendar_days_after(anchor, [boundary]) -> decimalCalendar days after anchor up to boundary (optional)
timing.trading_days_in(anchorA, [anchorB], [a_boundary], [b_boundary]) -> decimalTrading‑day count within a window
timing.calendar_days_in(anchorA, [anchorB], [a_boundary], [b_boundary]) -> decimalCalendar‑day count within a window

Anchors & Boundaries

NameDescription
this_weekCurrent trading week anchor
next_weekNext trading week anchor
last_weekPrevious trading week anchor
this_monthCurrent calendar month anchor
next_monthNext calendar month anchor
last_monthPrevious calendar month anchor
this_quarterCurrent calendar quarter anchor
next_quarterNext calendar quarter anchor
last_quarterPrevious calendar quarter anchor
this_yearCurrent calendar year anchor
next_yearNext calendar year anchor
last_yearPrevious calendar year anchor
monthly_opexMonthly options expiration (3rd Friday for standard index/equity options)
vix_settlementVIX settlement event anchor
triple_witchingTriple witching event anchor
quad_witchingQuadruple witching event anchor
firstStart boundary of the selected period/window
lastEnd 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.