if (curPosition > 0 and bar_dict[context.s].last < minn):
context.tradingSignal = 'exit'
else:
if (curPosition > 0 and bar_dict[context.s].last < getStopPrice(context.firstOpenPrice, context.units_hold, atr)):
context.tradingSignal = 'stop'
else:
if (bar_dict[context.s].last > context.max_add and context.units_hold != 0 and context.units_hold < context.units_hold_max and availableCash > bar_dict[context.s].last*context.unit):
context.tradingSignal = 'entry_add'
else:
if (bar_dict[context.s].last > maxx and context.units_hold == 0):
if (context.tradingSignal != context.preTradingSignal or (context.units_hold < context.units_hold_max and context.units_hold > 1) or context.tradingSignal == 'stop'):
if context.tradingSignal == 'entry':
context.quantity = context.unit
if availableCash > bar_dict[context.s].last*context.quantity: