Another thing I see glancing back at this is that if you're entering below the VWAP at a percentage threshold, it should be the price you purchased the stock at multiplied by the max loss. Also, if you're already below the discount threshold, there's no reason to buy at a higher price. Technically:
for s in context.security_listF:
if s not in context.portfolio.positions and data.can_trade(s) and s not in get_open_orders():
cp = data.current(s,'price')
if cp < (vwap(data,context,s) * VWAP_DISC):
# price at current price if less than vwap entry point
tc(lp,[s,context.pctx, cp,False],[s.symbol + ' => Market Long','Error'])
context.trail[s] = cp * MAX_LOSS
tc(so,[s,0,context.trail[s],False],['Stop Price set','Error'])
else:
tc(lp,[s,context.pctx, vwap(data,context,s) * VWAP_DISC ,False],[s.symbol + ' => Market Long','Error'])
context.trail[s] = vwap(data,context,s) * VWAP_DISC * MAX_LOSS
tc(so,[s,0,context.trail[s],False],['Stop Price set','Error'])
This increases the percentage gain, as you're obviously avoiding situations where you're buying higher at a lower price, which is probably a good idea if you're going long. #duhhh