I had to copy and paste my code because it can't yet run a backtest...I've tried to manipulate the basic momentum backtest from quantopian
Starting at the bottom of my code: if the most recent 1m volume is > any previous minute during the current trading day * 500% I want to open up a position of 100 shares. -- How do I get the most recent minute's volume to compare to every respective minutes' trading volume or, more simply, initiate a position if the most recent 1m volume is 500% greater than the highest 1m volume of the current day.
I would love to use the schedule_position function and restrict this to placing trades only between 12pm-1pm, but I want it to look at the volume history of each minute since 9:30 -- I didn't even know where to begin to put this in.
Thanks for the help.
def initialize(context):
context.aapl = sid(24)
def handle_data(context, data):
volume = history(60, '1m', 'volume')
volume = data[context.aapl].volume
if 1m volume > any previous 1m volume histroy of current day * 5.0:
order(context.aapl,+100)
log.info("Buying %s" % (context.aapl))