How to exit a strategy on the basis of time?

You can create a condition as following for time-based exits:

Let’s say you want to exit the strategy after 3:15 PM if none of the exit conditions were met till 3:15 PM. The timeframe (resolution) of your strategy is 15 min.

The 23rd 15 min candle of the day for equity opens at 3:00 PM and closes at 3:15 PM. You can add the following exit condition

Nth Candle (Close, 15min, 23) higher than 0

This will check whether close price at 3:15 PM is higher than 0 or not. Since in all cases, it will be true (not considering Crudeoil Fut :wink:) you will get an exit notification at 3:15 PM.

The candle number is dependent on the candle timeframe. If you use a 5 min timeframe, the 3:15 PM candle will be number 72.

2 Likes

Thanks. Similar method I had found and it is working except for 3.15 PM case where it is going for square off in place of exit. I think there is a need to change in coding/logic of square off any MIS trade. Earlier Zerodha had policy of squaring trade at 3.15 PM which has been changed now to 3.20 PM however in steak, the old timing of is in effect as every MIS trade are being squared off at 3.15 pm.