My stop order doesn't work even I set it to 0.999
Is it because I have put it in the "handle_data" and it keeps changing?
STOP_LOSS = 0.999
def handle_data(context,data):
MAX_LEVERAGE = calc_leverage(context.portfolio.cash)
context.pctx = diversify(context,data,context.security_listF,MAX_LEVERAGE)
if context.pctx == 0:
return
for s in context.security_listF:
cp = data.current(s,'price')
if s not in context.portfolio.positions and s not in get_open_orders():
#if context.portfolio.cash > 0:
if data.can_trade(s):
order_target_percent(s,context.pctx,style=MarketOrder())
context.sl[s] = cp * STOP_LOSS
order_target(s,0,style=StopOrder(context.sl[s]))