Hi guys,
I thought the order_target method was set up to avoid buying or selling more than a given percentage of stocks.
This application went absolutely berzerk after I changed the moving average to a shorter period, which should not have affected anything.
Both on buy and sell side it goes crazy, buying and selling way in excess of margin. But why?
Here's how I am measuring number of max shares to buy/sell
context.posValue = math.floor(context.portfolio.portfolio_value * context.longLeverage /len(context.assets) )
new_price = data[stock].price
sharesToTransact = math.floor(context.posValue/new_price)
order_target(stock,sharesToTransact, style=LimitOrder(limitPrice))
I am using a
if get_open_orders(stock) : ... continue
method to skip ordering several times until orders have filled.
So what gives?
Probably something simple, but I cannot find it.
Thanks