The QRS detection is a crucial step in ECG signal analysis; it has a great impact on the beats segmentation and in the final classification of the ECG signal. The Pan-Tompkins is one of the first and best-performing algorithms for QRS detection. It performs filtering for noise suppression, differentiation for slope dominance, and thresholding for decision making. All of the parameters of the Pan-Tompkins algorithm are selected empirically. However, we think that the Pan-Tompkins method can achieve better performance if the parameters were optimized. Therefore, we propose an adaptive algorithm that looks for the best set of parameters that improves the Pan-Tompkins algorithm performance. For this purpose, we formulate the parameter design as an optimization problem within a particle swarm optimization framework. Experiments conducted on the 24 hours recording of the MIT/BIH arrhythmia benchmark dataset achieved an overall accuracy of 99.83% which outperforms the state-of-the-art time-domain algorithms.