BackgroundMathematical models to forecast the risk trend of the COVID-19 pandemic timely are of great significance to control the pandemic, but the requirement of manual operation and many parameters hinders their efficiency and value for application. This study aimed to establish a convenient and prompt one for monitoring emerging infectious diseases online and achieving risk assessment in real time.MethodsThe Optimized Moving Average Prediction Limit (Op-MAPL) algorithm model analysed real-time COVID-19 data online and was validated using the data of the Delta variant in India and the Omicron in the United States. Then, the model was utilized to determine the infection risk level of the Omicron in Shanghai and Beijing.ResultsThe Op-MAPL model can predict the epidemic peak accurately. The daily risk ranking was stable and predictive, with an average accuracy of 87.85% within next 7 days. Early warning signals were issued for Shanghai and Beijing on February 28 and April 23, 2022, respectively. The two cities were rated as medium–high risk or above from March 27 to April 20 and from April 24 to May 5, indicating that the pandemic had entered a period of rapid increase. After April 21 and May 26, the risk level was downgraded to medium and became stable by the algorithm, indicating that the pandemic had been controlled well and mitigated gradually.ConclusionsThe Op-MAPL relies on nothing but an indicator to assess the risk level of the COVID-19 pandemic with different data sources and granularities. This forward-looking method realizes real-time monitoring and early warning effectively to provide a valuable reference to prevent and control infectious diseases.