A relationship of the vertical field Bz required to maintain horizontal stability and the ratio of the central line-averaged density to the plasma current is deduced and is proved to be linear through the previous statistical discharge data on the J-TEXT tokamak. According to this, a plasma horizontal position control system based on feedforward density compensation (FDC) is developed and tested on the machine for different ramping rates of density variation. Due to the feedforward density signal, the controller with FDC could suppress the disturbance of the horizontal displacement owing to the density variation during the flat-top phase moving more quickly when compared with the case with the traditional proportional–integral–derivative controller, which is a feedback controller. There is a trade-off between the suppression of the perturbation and the oscillation of the horizontal displacement for density variation, which should be taken into account in real routine discharge.