When I buy a stock, I record the date and time like this:
# Record date
context.Start_Date = data[stock].datetime
I also perform stop-loss checks every tick in "handle_data()". I want to prevent my algo from performing a stop-loss calculation if today is the same day I bought the stock. How can I do this?
# Stop Loss logic
# Skip the stop loss check if there is an open order for the stock
if get_open_orders(stock):
return
# Don't process stop loss on entry day
# This code gives an error "Runtime exception: KeyError:"
# I only want to compare the date, not time. Can I do this? "data[stock].datetime.day"
if data[stock].datetime == context.Start_Date:
return