I am getting the error in my trailing stop. I move the stop up depending on the maximum value for the new stop and the previous stop value. I am getting an error when I test whether the price > context.stop[stock]. It says price is referenced before assignment. I just added the rebalance into it, which rebalances based on the volatility weighting, and the rebalance threshold.
if price < context.stop_price[stock]: