A new seismic early warning algorithm is presented that estimates a magnitude threshold using the first 3 s of the P‐wave coda on the vertical component. The algorithm considerably reduces the processing time compared to previous algorithms used by the Mexican seismic early warning system (Seismic Alert System of Mexico [SASMEX]). It was designed to alert earthquakes within the subducted Cocos plate. The algorithm was based on a training dataset of 76 accelerograms of 25 Mexican in‐slab earthquakes, with focal depths . The algorithm uses two parameters based on the unfiltered vertical component of the P waves: the sum of the cumulative quadratic acceleration, and a parameter that represents the slope of the cumulative acceleration. The model is based on a learning machine that linearizes piecewise the empirical relation between these two parameters and magnitude . The resulting algorithm was tested on nine earthquakes that took place from 2014 to 2017, recorded in 37 strong‐motion records. In addition, the algorithm was evaluated in the context of the Mexican earthquake early warning, applying it to 24 in‐slab earthquakes occurring from 1995 to 2017 (). The magnitude of 19 earthquakes was properly estimated; for four of them, it was overestimated and in one case the magnitude was underestimated. Three earthquakes that affected Mexico City were included in the dataset: the 6.5 event on 11 December 2011 and the destructive in‐slab Tehuacán and Morelos earthquakes on 15 June 1999 ( 7.0) and 19 September 2017 ( 7.1). The retrospective application of the algorithm shows that these three earthquakes are correctly identified as and would activate a seismic alert. The algorithm would have given an advance warning of 34, 35, and 16 s respectively, before the arrival of strong motion in Mexico City.