New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

Need help writing a scan

I would like to write a scan to give me a list of stocks when meeting all three of the following criteria.
1. Price breaks the 200 dma.
2. Volume more than twice the average trading of the past four weeks.
3. RS line breaks into positive territory from a neutral or negative territory.

Best Answer

  • lmkwinlmkwin ✭✭
    edited February 2023 Answer ✓
    I provided you with Help in the 1st response. Let's see how writing out the steps for you helps.

    On the Scan Workbench, select your DMA of choice from the Technical Indicators dropdown.

    Change the

    and [EMA(50,volume) > 9999999]

    // you wanted the price to break the ma. This is the price crosses above the ma code
    and [close x EMA(200,close)]

    then copy that line and paste it in the next line below

    and [close x EMA(200,close)]
    and [close x EMA(200,close)]

    change the 2nd line to look at volume compared to the average of the past 4 weeks (20 days)

    and [close x EMA(200,close)]
    and [volume > EMA(20,volume)]

    now, you want it to be twice as big as the MA volume so we need to multiply the MA volume by 2

    and [close x EMA(200,close)]
    and [volume > EMA(20,volume) * 2]


  • A great starting point for any scan is to use the scans that have already been written and then modify them to meet your requirements.

    The Predefined Scans page has many different daily scans available for your use. Click on the one you want and then in the upper row there is a button link to Edit Scan Criteria.

    This will open that scan to the scan workbench and you can edit/modify/run/save that scan to your account to use anytime you want to.

    They have Volume movers, price crossing moving averages, and a whole bunch more.

    RS line is going to be your tough one. There is no predefined scan

    The only thing that you have in the workbench is PctRelative, which computes a value over a period of time. You'd have to pick your time period. Example PctRelative 200,RSP is going to give a value of the relationship of the symbol and the RSP over 200 periods.

    PctRelative 200 RSP > 0 and 5 days ago PctRelative 200 RSP < 0 would be your option on RS. It doesn't chart that way though. I have no idea why they haven't figured a nifty way to show PctRelative. It would be nice to have RRG as scan options, but they aren't in there yet. Now that Julius de Kempenaer is officially a StockCharts staff member, perhaps that will change.

    On the chart you only have RRG and the Price/Price Performance options to show RS. Another option is to ignore the RS requirement in your scan. Save the results of the 1st two requirements to a chartlist and then use the Performance view of that chartlist and put in the Compare To symbol you want to use for the RS calculation. They list several time periods on the Performance view. Click on the period header of choice to sort and then scroll down to where the Perf number is around the zero level. Those would be the ones that you may want to look at for "was neutral or negative breaking into positive.

  • So how would you write the 1st two requirements?
    1. Price breaks the 200 dma.
    2. Volume more than twice the average trading of the past four weeks.
  • Another option to find the MA breaks is to use the newer Distance from MA filters. They added one for EMA and SMA. The value is the percentage difference between the price close and the MA for the closing prices in the period.

    In the Technical Indicators drop down, they are both listed in the top section. The Distance from SMA defaults to this:

    and [DistFromSMA(200) > 0]

    This expression It is asking that the current close is above the SMA 200 close by any amout greater than 0 percent.

    To use this for a "break above", I'd use a comparison vs a X crossing option.

    A comparison looks at a prior period(s).

    and [[DistFromSMA(200) > 0] and [5 days ago DistFromSMA(200) < 0]]

    This comparison looks at the current value being greater than 0 percent, or above the MA, and 5 days ago the value was a negative percent, or below the moving average.

    The DistFrom works with Price ONLY. With the other MA filters, you've seen that you can use other values, like Volume, or PPO, or pretty much any other value stored in the database. So DistFrom has some plusses and minuses but it's available for use and is very straight forward way to find and compare securities. You can use it in a Rank By statement as well.

  • You could try using SCTRs as substitute for RS. You would have to decide what SCTR value(s) (from 1 to 100) constitute neutral/negative/positive territory. Since the scale is 100, presumably anything above 50 is positive, but you would have to decide if that is positive enough, or do you want > 60, 70, 80, etc. Also, you would need to scan for the SCTR direction improving over time, so today's value > 20 days ago for instance.

    As for "breaking into" positive territory on the same day that price breaks the 200 and volume increases dramatically, that trifecta is likely pretty rare. I think I would just test for a positive territory and improving SCTR.

    Also, you might have better luck on a weekly chart - weekly close x weekly sma(40, weekly close) and weekly volume > weekly sma(13, weekly volume) * 4 (or whatever). That way, you don't have to pinpoint the exact day of crossover - which may or may not correspond precisely with a surge in volume. Volume surges can be caused by technical events, but are more likely to be caused by news, like surprise earnings, patent approval, etc.
Sign In or Register to comment.