I am trying to build a strategy which will take trades only on the day of expiry and on the previous day of expiry i.e. on wednesday and thursday in case of BankNifty. I have built the entry condition as shown in the screenshot attached. But the strategy is taking trades only on the expiry day and not on the previous day of expiry.
In the above condition, we are checking if the difference between the Current month expiry and today is greater than 15 days.
It considers all calendar days including holidays and non-trading days. You can find more detail on this keyword in the video link shared below:
Tradetron TeamTradetron team
Tomorrow returns the next calendar date as text (YYYY-MM-DD). It is true on the day before expiry only if that day is literally one calendar day earlier, and only when you compare it with a date string such as an expiry keyword. A common mistake is comparing it with a number, or with an expiry keyword for a different underlying or expiry.
Recommended: trade on expiry day and the trading day before
Use two checks joined with OR:
Expiry day: Today('NSE') == Current Week Expiry('NIFTY BANK', 0)
Day before (skips holidays and weekends): Next Trading Day('NSE') == Current Week Expiry('NIFTY BANK', 0)
Next Trading Day uses the NSE holiday calendar, so if the day before expiry is a holiday it still picks the right day.
Alternative: days to expiry
Days Difference(Today('NSE'), Current Week Expiry('NIFTY BANK', 0)) <= Number(1) counts calendar days, so a holiday in between can make it miss.
Use the expiry keyword that matches the contracts your index actually lists (Current Week or Current Month). Expiry weekdays change over time, so don’t hard-code a weekday. Test in Live Offline.