We present a new model for the creation of $J/\ensuremath{\psi}$ mesons in ultrarelativistic heavy ion collisions, which allows one to follow the individual heavy quarks from their creation until the detector through the quark-gluon plasma, which is formed in these collisions and described by the EPOS2 event generator. The $c$ and $\overline{c}$ quarks interact via a potential, based on results of lattice gauge calculations. The annihilation and creation of $J/\ensuremath{\psi}$ is described by a density matrix approach whose time evolution is studied in the expanding system. The comparison with PbPb data at $\sqrt{s}=5.02$ TeV shows that this model can describe simultaneously the nuclear modification factor ${R}_{AA}$ and the elliptic flow ${v}_{2}$ of the $J/\ensuremath{\psi}$ at low transverse momentum. Perspectives for further improvement are discussed.