I think there may be a logic flaw in if(TradePriceClose). TradePriceClose is literally the price in which the trade itself closed, so why would the closing of the trade generate a new stop for a trade that has already closed?