Thanks to Grant, Dan and Dennis for helping me get this far.
I have an error on line 38 that I cannot quite figure out.
I want my algorithm to buy if the current price is between open + .10 and open + .20. Then sell if price is below open - .20 or the start of a new day.
def initialize(context):
context.nflx =sid(23709)
context.initialize = True
context.event_day = 0
context.first_day = False
context.new_day = False
context.day_counter = 0
context.bought = False
# setup list of stocks to trade (or call set_universe)
context.stocks = [sid(23709), sid(24791)] #NFLX, CSTR
#set_universe(universe.DollarVolumeUniverse(98.0,99.0))
def handle_data(context, data):
event_datetime = data[context.stocks[0]].datetime
event_day = data[context.stocks[0]].datetime.day
if context.initialize:
context.event_day = event_day
context.initialize = False
context.first_day = True
if event_day != context.event_day:
context.new_day = True
order(context.nflx,-100)
context.bought = False
else:
context.new_day = False
if context.first_day or context.new_day:
context.day_counter = context.day_counter + 1
price = data[context.nflx].price
if price + .10 <= data[context.nflx].price <= price + .20:
order(context.nflx,100)
context.bought = True
print event_datetime
print 'Order submitted'
if context.bought = True
if data[context.nflx].price <= price - .20:
order(context.nflx,-100)
context.bought = False
context.first_day = False
context.event_day = event_day