When writing code its very easy to get "stuck in the weeds". This happens when become so focused on trying to solve the puzzle that we forget to look for the most simple solution.
The alert you describe is something that I have been using for years on Thinkorswim. And the solution is only a single line of code:
low is less than (close[1] * 0.98)
The rest of the are handled further upstream, in the settings you adjust when creating a Study Alert. I could probably do a video on this topic, because there are a lot of ways this tool can be applied. But here are a few screenshots which demonstrate how I create my own alert that triggers when ticker symbol /NQ drops more than 2% below the prior session close.
I'll provide a brief overview to guide you through the screenshots I have included below:
- From MarketWatch -- Alerts on the main Thinkorswim window, click the Study Alert button
- Click to the select the "thinkScript Editor" section, then enter your code in the code editor
- Click the button on the bottom left named "+ Set Alert Rules..."
- In that window, you need to make sure to check those two boxes I have noted in the third screenshot below.
Checking these buttons means the alert will be recreated each time after it has been triggered. Create one alert, and let it run for years without any need to touch it again.
Yeah... I know. Sometimes the simplest solutions can really blow our minds. If you enjoyed this solution, please tell everyone you know.