I updated the title of your question to include one of the most important details, which is the description of what this chart study does. I also moved your question out of the "Alerts and Notifications" topic and into the "Chart Studies" topic since you are working with a chart study.
This code is reading one bar into the future in order to position the plots and chart bubbles. Which means the signals you are trying to use for your chart alerts will never appear on the last bar on the chart. They will only appear on the next to the last bar on the chart. And they are subject to vanish from the chart if the conditions change before the last bar on the chart closes. (this means you will have some alerts which fail to lock in)
Now that we understand how the code is working, we can apply a modification to get the alerts to work correctly. In order for your alert to function you must apply an index to the variable name so that is it looking at the previous bar instead of the current bar. Your current alert statements look like this:
Alert(BullRetrace, "BULL SWING", Alert.TICK, Sound.Ring);
Alert(BearRetrace, "BEAR SWING", Alert.TICK, Sound.Ring);
The only way to get these alerts working for this specific chart study is to apply the index to the variables as shown below:
Alert(BullRetrace[1], "BULL SWING", Alert.TICK, Sound.Ring);
Alert(BearRetrace[1], "BEAR SWING", Alert.TICK, Sound.Ring);
The same issue is preventing your chart background statement from working correctly. Now that you understand how to adjust the alerts statements to work with this code you should be able to workout the chart background color statement in like manner.