We aim to provide an algorithm to predict the distribution of the critical times of financial bubbles employing a log-periodic power law. Our approach consists of a constrained genetic algorithm and an improved price gyration method, which generates an initial population of parameters using historical data for the genetic algorithm. The key enhancements of price gyration algorithm are (i) different window sizes for peak detection and (ii) a distance-based weighting approach for peak selection. Our results show a significant improvement in the prediction of financial crashes. The diagnostic analysis further demonstrates the accuracy, efficiency, and stability of our predictions.