So I'm just trying to create SMA's but can't figure it out. can someone help? I just want to buy if SMA5 > SMA10.
Put any initialization logic here. The context object will be passed to
the other methods in your algorithm.
def initialize(context):
context.spy = sid(8554)
context.max_notional = 5000.0
context.min_notional = -0.0
set_long_only()
pass
Will be called on every trade event for the securities you specify.
def handle_data(context, data):
current_price = data[sid(8554)].price
price = data[sid(8554)].price
cash = context.portfolio.cash
notional = context.portfolio.positions[sid(8554)].amount * price
# Trying to create a sma
SMA5 = history(bar_count=5, frequency='1m', field='price')
log.info(SMA5.mean())
SMA10 = history(bar_count=10, frequency='1m', field='price')
log.info(SMA10.mean())
SMA20 = history(bar_count=20, frequency='1m', field='price')
log.info(SMA20.mean())
# Implement your algorithm logic here.
# data[sid(X)] holds the trade event data for that security.
# context.portfolio holds the current portfolio state.
# Place orders with the order(SID, amount) method.
# TODO: implement your own logic here.
if (cash > current_price) and (SMA5 > SMA10):
order_value(sid(8554), 5000)