I am having some issues on finding a way to exit a position after it is open for X minutes. Perhaps someone has a good solution to this? Currently I convert the time to minutes by:
exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern') t = exchange_time.minute+exchange_time.hour*60
I store the minute the position is opened and if current t is greater than X minutes I will exit. some positions were remaining open though, I added a line to print t at every minute bar and got this:
Every so often there is a huge jump in t which should just be the time converted to minutes. So when I happen to open a position when t spikes, it will never close. Does anyone know why this is happening?