Condition for the trading day before expiry (holiday-safe) — Tradetron Community
← Community

Condition for the trading day before expiry (holiday-safe)

Uncategorized 1,352 views

Uma Sundar

Hi,

I need a condition to check trading day which is one day before expiry or one day after previous expiry.

As Days Difference keyword takes all calendar days, it is not feasible to use it in Algo Trading. For example If I use this to exit one day before expiry then it will try to execute on Wednesday since Thursday is a expiry day for Nifty. What if Wednesday is a public holiday? It won’t work right? Same case for entry as well. I want to take trade one day after previous expiry. How to set it? There is no option available and if Friday is public holiday then it won’t take trade on next trading day that is Monday.

I need a dynamic solution. Otherwise, it is not a Algo Trading.


Question:

Regarding days difference , does it take into account all days or only trading days;

Solution:

All calendar days

so on expiry days difference will be 0, Assuming 3/11/21 is the expiry,
on 02/11/21 it will be 1
01/ 11/21 it will be 2
31/10/2021 = 3
30/10/2021 = 4

Please provide a solution.

Regards,
Uma

Tradetron Team Tradetron team

One trading day before expiry (holiday-safe): use Next Trading Day:

Next Trading Day('NSE') == Current Week Expiry('NIFTY 50', 0)

This is true on the last trading day before expiry, even if the normal day before is a holiday. Use Current Month Expiry for monthly.

One trading day after the previous expiry: there is no “previous trading day” keyword. A close approximation is Days Difference (D2-D1) ( Previous Expiry('NIFTY 50', 'Week', 0), Today('NSE') ) >= Number(1) with a run-once runtime gate so it trades only the first day it becomes true.

Note: Next Trading Day follows the NSE calendar. Test it in Live Offline before going live. Keyword reference: Keyword Documentation — Tradetron

:sparkles: Answer written with AI from Tradetron docs (Oct 2026). Original replies are kept above. Spot something wrong? Reply below.