This is one of the powerful features of the StockCharts scanning engine and I'm sure once you've mastered it you'll use it in most of your scans, in one from or another.
Lets start with looking at one of the predefined scans and see how it's constructed. This is also one of the best ways to learn about building your own scans.
Pull up the Standard scan engine and in the bottom right hand corner you can select and insert one or more of the available predefined scans, note its best to review (study) them one at a time. AND you can also modify and /or combine any of them to suit your personal scanning needs.
In the Standard Scan Engine, we'll now see the following coding.
We see the scan requires the current "High" today (ie 0 trading days ago) to be > "greater than" the Max. High observed anywhere over the previous 260 days, starting yesterday (ie 1 day ago). Note if we didn't specify starting "yesterday" for this "Max High" part of the criteria then this section would also include todays high which is contained in the first 'High" criteria section and thus no stocks would meet the criteria.
In the Advanced Scan Engine, we would see the following coding. Note you can see the Advanced coding for any Standard scan by just pressing the "Advanced User Interface" button at the bottom of the scan page. All coding will be converted and displayed in the Advanced format.
If we wanted a new high "Close" instead of just the "High" (which could be an intraday high), there is no canned scan for this but we can modify the coding above. Just replace the High with Close and replace the Max. High with Max. Close, from the dropdown menus as follows.
In the last article "Scanning for Near Crosses", Jack posted the following question in the comment section. (thanks for your input Jack)
"…I want to scan for stocks that have been in an uptrend for a minimum of the last 60 days and have been in a tight consolidation for a minimum of the last 7 market days. Over this 7 day period the price has not varied more than plus or minus .6% from the mean price of the 7 day period. Does that make sense? Is such a scan possible?..."
This is a prime example of using the Min Max over time functions, with respect to the uptrend section of the question we'll just use something simple like requiring the current 20 day SMA to be 5% greater than the 20 day SMA from 60 days ago.
Now for the consolidation section we want the Max close during the last 7 days to be less than the current 7 day SMA plus 0.6%, (SMA(7) * 1.006). And we want the Min close during the last 7 days to be greater than the current 7 day SMA less 0.6%, (SMA(7) * 0.994). Thus the scan criteria would look like this in the Basic scan engine, to see the coding in the Advanced scan engine just press the "Advanced User Interface" button at he bottom of the screen.
Note this may not look like your standard chart but for ease of verifying the scan I always set up a default chart that closely mirrors the scan criteria and eliminates all other information that’s not in the scan. Thus I've set up the chart above to have a 3 months duration, selected just the closing prices as dots, SMA-20 and shown only the SMA-7 moving average envelopes with a +/- 0.6% range, that’s the ENV(7, 0.6).
If you're an Extra member save the chart settings as default, then from the scan output window I save the contents to my "00 Temp" folder (starts with 00 so its always the first on the list, just hit go). Then on the next screen switch from "Summary" to "10 per Page View" and all you charts are displayed with the default chart settings that mirror the scan to be verified. This makes the review quick and if you spot anything which does not meet the criteria, then its back to the scan coding page to see where you went wrong, usually its some < or > symbols backwards, or some missing brackets, or an error in the logic.
Hope this gives you some new ideas. I'll leave the comments section open for a few days, however don't expect an immediate response as I only have time to check in here every couple of days.Good luck scanning.