Hi Lucas,
Thanks for sharing your problem! There are a couple of ways to go about doing this. The first way is to use 'set_max_order_size' and put a try/except block around your order statement like so:
try:
order(sid(24), 100)
except:
print "No More Orders For Today
This way you no longer have the trading guards stopping your algorithm mid-run. The problem with this however is that if you have two orders for 60 shares, it will only execute the first 60 and won't execute the last 40 (assuming the max number of shares you specified is 100).
The way to alleviate that problem is to use this solution (which works in minutely mode):
import numpy as np
import talib
def initialize(context):
context.sid = sid(24)
context.max_order_size = 100
context.total_ordered = 0
context.day = 0
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
#: At the start of each day, reset the number of total ordered stocks
if get_datetime().day != context.day:
context.total_ordered = 0
context.day = get_datetime().day
if context.total_ordered < context.max_order_size:
#: Define order size
order_size = 94
#: If order size is too big calculate a smaller order size
if order_size + context.total_ordered > context.max_order_size:
order_size = context.max_order_size - context.total_ordered
#: Use the smaller order size
order(context.sid, order_size)
context.total_ordered += order_size
Let me know if you need any more help
Seong
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.