When you close a position, its profit or loss is added to your balance.
To close an active position at market price, click on the X next to your position in the Positions panel.
You can also close your position at a predetermined take-profit and/or stop-loss price. Simply click on your position then on the TP/SL tab to set those.
Keep in mind
Buy positions are closed at the bid price and sell positions are closed at the ask price.