How to add an alert to an indicator?

 

How would I go about creating an alert (pop up and sound) if say slow stochastic's is below 20?  Would I have to rewrite the whole stochastic's indicator in a script?  Rewrite the indicator as a class object?  Could I simply add it to the stochastic's indicators' script?  Or simply reference it from a new script?

I tried adding it to the indicator itself, but it just breaks the whole thing. I only want it in real time, not retrospectively like a backtest.
 
antiseptic: I tried adding it to the indicator itself, but it just breaks the whole thing.

Adding it to the indicator does break anything. You broke it.

Either after the main loop, or in a new indicator, on a new bar, get the stochastic values for bar 2/1 and test for an alert.

Scripts are for one time execution.

Reason: