Category
General-Purpose Functions
Description
Whether current bar date is nth specific weekday of current month
Syntax
NthOfMonth(weekday, nth)
Parameters
weekday - 1 = Monday, 2 = Tuesday, ..., 7 = Sunday
nth - 1 = first from start, -1 = first from end, 2 = second from start, -2 = second from end, ...
Return Value
1 if the current bar's day of week is the specified weekday and it is the nth instance of that weekday in the current month, else 0.
(Again, where nth means from the start if positive, or from the end if negative.)
Notes
This function applies to the date of the current bar being evaluated.
The current bar must be the specified weekday for the result to be true.
The other instances of that weekday that determine whether the current bar is the "nth" do NOT have to be market days.
For example Monday September 9 is the second Monday in US markets even though the 2nd was a holiday (labor day).
Examples
IsThirdFriday: NthOfMonth(5, 3)
IsFinalTuesday: NthOfMonth(2, -1)
To find a past or future NthOfMonth date, use e.g.
PrevFirstMondayDate: WhenTrue(NthOfMonth(1, 1), BarDate)
NextThirdFridayDate: WhenTrue(NthOfMonth(5, 3), BarDate, 0, -1)
Note that future NthOfMonth values cannot be determined beyond the last date of the current data file, i.e., they are only usable in backtests, not in order generation.
|