Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
one hour of algo activity

Hi i was wondering how to make my algorithm work only for the first hour of market. I want in fact to make it stop automatically only if i don't have any open positions. Any clue?

this is what i made but i think is not that great and is missing the second part

from datetime import datetime, timedelta
start = datetime.now()
while datetime.now() - start < timedelta(seconds=1*60*60):
perform(True)
perform(False)

1 response

Where is this supposed to run, as a backtest on quantopian or on your computer / a cloud server to trade live?
datetime.now() returns the current system time of the computer where the algorithm is running and has nothing to do with market hours unless you scheduled a cron job or something to execute the python script at market opening.