We investigate the properties of anisotropic, spherically symmetric compact stars, especially neutron stars and strange quark stars, made of strongly magnetized matter. The neutron stars are described by SLy equation of state, the strange quark stars by an equation of state based on the MIT Bag model. The stellar models are based on an a priori assumed density dependence of the magnetic field and thus anisotropy. Our study shows that not only the presence of a strong magnetic field and anisotropy, but also the orientation of the magnetic field itself, have an important influence on the physical properties of stars. Two possible magnetic field orientations are considered, a radial orientation, where the local magnetic fields point in the radial direction, and a transverse orientation, where the local magnetic fields are perpendicular to the radial direction. Interestingly, we find that for a transverse orientation of the magnetic field, the stars become more massive with increasing anisotropy and magnetic field strength and increase in size, since the repulsive, effective anisotropic force increases in this case. In the case of a radially orientated magnetic field, however, the masses and radii of the stars decrease with increasing magnetic field strength, because of the decreasing effective anisotropic force. Importantly, we also show that in order to achieve hydrostatic equilibrium configurations of magnetized matter, it is essential to account for both the local anisotropy effects as well as the anisotropy effects caused by a strong magnetic field. Otherwise, hydrostatic equilibrium is not achieved for magnetized stellar models.