Near a black hole or an ultracompact star, the motion of particles is governed by a strong gravitational field. Electrically charged particles also feel the electromagnetic force arising due to currents inside the star or plasma circling around. We study the possibility that the interplay between gravitational and electromagnetic actions may allow for the stable, energetically bound off-equatorial motion of charged particles. This would represent the well-known generalized Störmer's 'halo orbits', which have been discussed in connection with the motion of dust grains in planetary magnetospheres. We demonstrate that such orbits exist and can be astrophysically relevant when a compact star or a black hole is endowed with a dipole-type magnetic field. In the case of the Kerr Newman solution, numerical analysis shows that the mutually connected gravitational and electromagnetic fields do not allow the existence of stable halo orbits above the outer horizon of black holes. Such orbits are either hidden under the inner black-hole horizon, or they require the presence of a naked singularity.