Ultra-dense networks represent the trend for future wireless 5G networks, which can provide high transmission rates in dense urban environments. However, a massive number of small cells are required to be deployed in such networks, and this requirement increases interference and number of handovers (HOs) in heterogeneous networks (HetNets). In such scenario, mobility management becomes an important issue to guarantee seamless communication while the user moves among cells. In this paper, we propose an auto-tuning optimization (ATO) algorithm that utilizes user speed and received signal reference power to adapt HO margin and time to trigger. The proposed algorithm aims to reduce the number of frequent HOs and HO failure (HOF) ratio. The performance of the proposed algorithm is evaluated through simulation with a two-tier model that consists of 4G and 5G networks. Simulation results show that the average rates of ping-pong HOs and HOF are significantly reduced by the proposed algorithm compared with other algorithms from the literature. In addition, the ATO algorithm achieves a low call drop rate and reduces HO delay and interruption time during user mobility in HetNets.