Effect of pressure gradients and line-tying on the magnetic stability of coronal loops