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