Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
order_target_percent buying too much

I have a very simple part of my code which is making the algorithm over purchase shares which ends ups selling the next minute. I think it has something to do with open orders not being filled.

This is the code I have it purchases 100% of my money in certain stock, it usually ends up purchasing 110% percent of my money and the sells that 10%.

I tried to make a stop if there were orders, it is obviously not working though. If anyone has any ideas please let me know! Thank you!!

def handle_data(context,data):
values = data.current(context.aapl, 'price')
print values
datetime = get_datetime('US/Central')
letime = datetime.time()
hour = letime.hour
if hour < 14:
if no_orders:
data.can_trade(context.aapl)
order_target_percent(context.aapl, 100)

def no_orders(context):
no_orders = True
orders = get_open_orders()
if orders:
no_orders = False
return no_orders

4 responses

without seeing your indentation we can't tell what this issue is. bug might be that you're ordering regardless of if you have open orders or not

James thank you, attached is the indented code

you're forgetting to call no_orders. instead you are referring to the function in a boolean context so it always evaluates to true.

should be:
if no_orders(context):

Great James! Thank you so much!!