Spain treats capital gains and losses somewhat unfairly for non-residents. You have to pay for any gains, but you are not allowed to deduct any losses. The assumption is that you will be able to deduct these losses the taxes of your home country.
If you are moving here using the special “Beckham tax” rules, this is a bit tricky, because you may not have a home country to deduct the losses from.
Bottom line: don’t open a brokerage account here unless you are tax resident (or if you are such a genius that your trades never lose money).