have tried to understand the code and put the alerts myself, however it is something out of my understanding

The point is that it gives an alert when it is going to change from red to green or...