First off, great community. Love how helpful this forum is.
This is perhaps a dumb question but all of my orders fail to fill by the end of the day.
2016-02-04 WARN Your order for 100 shares of WMB failed to fill by the end of day and was canceled.
2016-02-11 WARN Your order for -251 shares of BETR failed to fill by the end of day and was canceled.
2016-02-16 WARN Your order for -4 shares of MTD failed to fill by the end of day and was canceled.
2016-02-24 WARN Your order for -62 shares of MRKT failed to fill by the end of day and was canceled.
2016-02-26 WARN Your order for -55 shares of XON failed to fill by the end of day and was canceled.
2016-03-01 WARN Your order for 17 shares of SFG failed to fill by the end of day and was canceled.
Below is my handle_data function which does all of my ordering.
I am really at a loss for why this is, I've set a filter for high volume stocks when setting up my pipe so I don't think it has to do with lack of volume (4 shares...).
Is there some check that I am missing before placing an order?
Grateful for any and all help as well as criticism.
def handle_data(context,data):
leverage = context.account.leverage
for stock in context.security_set:
if data.can_trade(stock) & not get_open_orders(stock) & (context.portfolio.positions[stock].amount == 0):
closes = data.history(stock, 'close', 10, '1d')
lows = data.history(stock, 'low', 10, '1d')
highs = data.history(stock, 'high', 10, '1d')
volumes = data.history(stock, 'volume', 10, '1d')
if leverage >= context.leverage_buffer:
return
elif stock in context.long_set:
if talib.ADOSC(highs, lows, closes, volumes, fastperiod=3, slowperiod=10)[-1] > 0:
order_target_percent(stock, 1. / context.num_securities)
elif stock in context.short_set:
if talib.ADOSC(highs, lows, closes, volumes, fastperiod=3, slowperiod=10)[-1] < 0:
order_target_percent(stock, -1. / context.num_securities)
for stock in context.portfolio.positions:
closes = data.history(stock, 'close', 10, '1d')
lows = data.history(stock, 'low', 10, '1d')
highs = data.history(stock, 'high', 10, '1d')
volumes = data.history(stock, 'volume', 10, '1d')
if leverage >= context.leverage_buffer:
order_target_percent(stock, 0)
elif context.portfolio.positions[stock].amount < 0 & data.can_trade(stock) & not get_open_orders(stock):
if talib.ADOSC(highs, lows, closes, volumes, fastperiod=3, slowperiod=10)[-1] > 0:
order_target_percent(stock, 0)
elif context.portfolio.positions[stock].amount > 0 & data.can_trade(stock) & not get_open_orders(stock):
if talib.ADOSC(highs, lows, closes, volumes, fastperiod=3, slowperiod=10)[-1] < 0:
order_target_percent(stock, 0)