The detection of QRS complexes is a crucial step in ECG signal processing since all subsequent analysis is very sensitive to the accuracy of this detection. This study presents an accurate and computationally efficient approach to heartbeat detection based on the enhancement of QRS complexes by means of a cascade of moving averages. The structure of this transformation is chosen automatically in the initialization phase of each record, through maximization of a signal quality index. Two types of elements are included: differences of centered moving averages of suitable size to reduce the amplitude of slow waves, such as baseline movements and T-waves; differences of shifted moving averages of varying size and delay which leads to a derivative behavior that enhances QRS. Heartbeat discrimination is performed on the absolute value of the transformed signal through adaptive thresholds, automatically initialized and updated after each detection. The proposed algorithm was evaluated on three Physionet’s ECG standard databases: MIT-BIH Arrhythmia, European ST-T and QTDB. Its performances were compared both to the results reported in literature and to the actual output of some publicly available QRS Pan-Tompkins detectors. On all the considered databases, our algorithm achieved an averaged accuracy (ACC) of 99.50% and a sensibility for atypical beats (SeA) of 96.92% while the best Pan-Tompkins (Behar’s) detector achieved ACC 98.72% and SeA 95.19%. The ACC score obtained on the first channel of the MIT-BIH Arrhythmia database is 99.86% and it is comparable to the best reported in the literature. In addition, our program processed, on average, one hour of signal in 0.11 s, while the fastest detector considered was about 4 times slower. In conclusion, the proposed method resulted as an accurate and fast approach for QRS detection, which overcomes the performance of the most common methods applied in the literature.