Hello this is my first algo that I am trying to build. It is obviously a very simple concept that I will try to build on in the future. I was wondering how I would add multiple stocks to the context and if I could run the same process of the five day period history on each of those stocks to determine when to buy?
The code is attached
Thanks!
def initialize(context):
context.security = sid(42950)
def handle_data(context, data):
average_price = data[context.security].mavg(5)
current_price = data[context.security].price
cash = context.portfolio.cash
if current_price > 0.95*average_price and cash > current_price:
number_of_shares = int(cash/current_price)
order(context.security, +number_of_shares)
log.info("Buying %s" % (context.security.symbol))
elif current_price > average_price:
order_target(context.security, 0)
log.info("Selling %s" % (context.security.symbol))