A strong candidate for a source of gravitational waves is a highly magnetized, rapidly rotating neutron star (magnetar) deformed by internal magnetic stresses. We calculate the mass quadrupole moment by perturbing a zeroth-order hydrostatic equilibrium by an axisymmetric magnetic field with a linked poloidal–toroidal structure. In this work, we do not require the model star to obey a barotropic equation of state (as a realistic neutron star is not barotropic), allowing us to explore the hydromagnetic equilibria with fewer constraints. We derive the relation between the ratio of poloidal to total field energy Λ and ellipticity ε, and briefly compare our results to those obtained using the barotropic assumption. Then, we present some examples of how our results can be applied to astrophysical contexts. First, we show how our formulae, in conjunction with current gravitational wave (non-)detections of the Crab pulsar and the Cassiopeia A central compact object (Cas A CCO), can be used to constrain the strength of the internal toroidal fields of those objects. We find that, for the Crab pulsar (whose canonical equatorial dipole field strength, inferred from spin-down, is 4 × 108 T) to emit detectable gravitational radiation, the neutron star must have a strong toroidal field component, with maximum internal toroidal field strength Btm= 7 × 1012 T; for gravitational waves to be detected from the Cas A CCO at 300 Hz, Btm∼ 1013 T, whereas detection at 100 Hz would require Btm∼ 1014 T. Using our results, we also show how the gravitational wave signal emitted by a magnetar immediately after its birth (assuming it is born rapidly rotating, with Λ≲ 0.2) makes such a newborn magnetar a stronger candidate for gravitational wave detection than, for example, an SGR giant flare.