In Type 1 diabetes (T1D) standard treatment, the mitigation of hypoglycemia is achieved by the assumption of small amounts of carbohydrates (CHO), called hypotreatments (HTs), as soon as hypoglycemia is revealed. However, since CHO takes time to reach the blood stream, hypoglycemia cannot be totally avoided. Our purpose is to evaluate in-silico the effectiveness of preventive HTs and to propose a new real-time algorithm for the mitigation/avoidance of hypoglycemia, based on continuous glucose monitoring (CGM) sensor data. To such a purpose, the algorithm exploits the "dynamic risk" non linear-function that, by combining CGM value and trend, allows predicting the forthcoming hypoglycemic event. The algorithm is tested in an ideal noise-free environment on 100 virtual subjects (VSs) generated by the UVA/Padova T1D simulator and undergoing a single-meal experiment, with induced post-meal hypoglycemia. Compared to a reference HT rule, which suggest to assume HTs when hypoglycemia is detected, the algorithm reduces, on median [25th - 75th percentiles], both the time spent in hypoglycemia (from 36 [29 - 43] min to 10 [0 - 20] min) and the post-treatment rebound (from 136 [121 - 148] mg/dl to 114 [98 - 130] mg/dl). In conclusion, the proposed real-time algorithm efficiently generates preventive HTs that allow to almost totally avoid hypoglycemia. Future work will concern to modify the algorithm for detecting in advance the severity of the hypoglycemic episode -since performance are influenced on the hypoglycemic episode aggressiveness level- and to assess algorithm in a more challenging environment, including CGM measurement error.