Sadly, although I originally thought it was possible, when I went to build this using the condition wizard I found it was not possible. So I’ll provide a modified version of your code that you can use in a Study Alert or the Study Filter of a custom scan.
Definition of Terms
To make things clear for all our viewers, I will take a few paragraphs to clear up some of terms you used. The phrase “Market Watch / Chart Scan”, has no meaning in the Thinkorswim platform. There is a tab on Thinkorswim called “MarketWatch”. Within that tab are various screens. One of which is named “Alerts”. In the upper right corner of that screen is a button named “Study Alert”. This is one location in which my solution can be applied. In summary, we have the following terms to help folks navigate the platform. 1. MarketWatch 2. Alerts 3. Study Alert.
There is another place my solution can be applied. That is within a Study Filter of a custom scan. There is a separate tab on Thinkorswim for scans. It is named “Scan”. Within that tab are various screens. The one my solution can be applied to is named “Stock Hacker”.
So from your original question we find the phrase “Chart Scan” does not exist anywhere on the platform. I felt it important to explain that to prevent other visitors to this post from getting confused.
The Code
Ok so this is the easy part. Your code already does the work. We just need to make some adjustments to adapt it to the Study Alert and/or Study Filter.
input fastLength = 50;
input slowLength = 200;
input tf = AggregationPeriod.FIFTEEN_MIN;
input offset = 0.5;
def HMAF = MovingAverage(AverageType.HULL, close(period = tf), fastLength);
def HMAS = MovingAverage(AverageType.HULL, close(period = tf), slowLength);
def rise = (HMAF > HMAF[1]) and (HMAS > HMAS[1]);
def fall = (HMAF < HMAF[1]) and (HMAS < HMAS[1]);
plot upsig = rise and !rise[1];
#plot dnsig = fall and !fall[1];
So what did I change? I removed all the plot and style statements at the end of the code. I also removed the Alert statement. Everything else is exactly the same. Well except for the last two lines. In the original, those were def statements and I changed them to plot statements. Since only one plot can be used at a time, I used a ‘#’ mark to turn the last line into a comment. To search for the other signal just move the ‘#’ mark.
Here is something that really surprised me. This code references a secondary time frame, 15 min. Previously, this was not permitted in Study Alerts. This means Thinkorswim has finally enabled secondary time frames for Study Alerts. Wonder if they also did so for Conditional Orders?
Screenshot below shows this code applied to a Study Alert set to 5 min time frame. Proving that we can indeed use secondary time frames on Study Alerts. Awesome!
Thank you Pete. This is what I was trying to do. Awesome.