I dont know why your Brokersell is not called, but when you set a variable or an ordertext it stays until you set another ordertext. It does not reset itself. NTRADES = 0 can mean not implemented or no trades, so use this command only when your broker plugin supports GET_NTRADES.