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.

Scan to catch a weekly divergence

I have a lot of experience analyzing technical charts but very little using the scan engine. Could somebody help me with 2 simple (I think) scans to catch a weekly divergence? On the chart below of XLI there are several divergences that I would have liked to catch with a scan. I would like to run these scans regularly on the various sectors of the market (like xli, xly, xlf, xlv, xlb, xlp, xlu, xlk). Specifically I would like to catch an sector etf which has been in a downtrend for at least 2 months and has a positive divergence in RSI (14) or in its relative strength (like xli:$spx). On the third week of Sept. 2015 there seems to be a divergence in xli:$spx and again in the second week of Jan 2016. Also, in the second week of Jan. 2016 there seems to be a positive divergence in the RSI of XLI (between the 4th week of Aug 2015 to the low in RSI in the 2nd week of Jan 2016).

How would I catch these? Thank you so much.

Best Answers

  • markdmarkd mod
    edited April 2016 Answer ✓
    Hi @BobS , welcome back!

    First, as far as I know, you cannot write a scan that directly queries the Price or Price Performance indicator (e.g. xli:$spx). You could write something that ranks a list of the sector SPDRs by ROC(x), or for that matter by RSI(x), and include $SPX in that list. Those that appear above $SPX are outperforming it over that time period for that indicator.

    // begin rank SPDR scan
    [favorites list is ??] // where ?? is the number assigned to your favorites list

    rank by ROC(x)
    // rang by RSI(14)

    // end scan

    You can toggle the rank by statements using the "//" comment symbols. The scan engine ignores lines that begin with "//" or "#".

    But that doesn't answer the question of divergence.

    Divergences are hard to catch in a scan because the time frames in which they occur are not consistent. For instance, the two lows you cite, August and January, are 23 weeks apart. Another instance might occur over 17 weeks or 38 weeks. So it's hard to write something that will catch everything. But, you can experiment with parameters to see what works more often.

    Basically, a divergence occurs when price reaches a new extreme, but its indicator doesn't, or vice versa.

    To test for the first type:

    // begin down side price divergence scan

    [favorites list is ?? ]

    and [weekly close = weekly min(26, weekly close)]
    and [weekly RSI(14) > weekly min(26, weekly RSI(14))]

    // end price divergence scan

    This catches everything making a new price closing low versus closes in the past twenty-six weeks (half a year), where RSI(14) is above its lowest low for that period. That lowest RSI(14) low might have occurred in any of the past 26 weeks.

    Since this is a weekly scan, be sure to set the run date to the last day of a week. Also, if you run it for past weeks, remember to set the end dates on your chart to correspond to the end date of your scan. It's very possible you will get no hits for weeks at a time.

    If you want indicator divergence (extreme reading on the indicator, price doesn't follow), reverse the placement of "close" and "RSI(14)" (so RSI(14) appears in the first line, close in the second line).

    For upside divergences, change "min" to "max" and ">" to "<".

    You really have to back test to see how many divergences actually occur and how often they actually work out. There is a lot of selective perception in reading charts by eye.
  • BobSBobS
    Answer ✓
    Thank you MarkD for the welcome back and for the superb answer. It is just what I was looking for. After I use these 2 scans for a while I may have some other questions. But this is great.
    I do have 2 forum questions at this time though.
    1. I received an email because I was mentioned in your post (thanks for that) but not because the question was answered, as I had in the old site. Is there something in my profile or somewhere that I need to check to receive notices of anytime my question is commented on or answered?
    2. Is there a place where I can change this from a discussion item to a question so that I can give you credit for answering my question. I do not see that here.

    Thanks again, so much.
  • gordgord admin
    Answer ✓
    BobS, yes welcome back.

    For notification settings look under your profile. Click the gear wheel in the top right corner, then select profile, then select notification settings. I have no idea what the best settings are for each individual, just select what you want, you can always change it later.

    With respect to "Question vs Discussion" I've changed this thread to a question for you. The default is "New Discussion" thats the button on the home page, but right beside it is a drop down arrow where you can select "Question" to start the thread.

    I would like to change the default to "Question" as that is the norm, but there seems to be no setting available for that.

  • markdmarkd mod
    edited April 2016 Answer ✓
    Hi @BobS ,

    The implementation isn't quite right. I wasn't really clear.

    Erase this line:

    [favorites list is 0099] // where ?? is the number assigned to your favorites list

    (I'm not sure why this ran without error.)

    Then, from the "Chart Lists" drop down, select the list you want to scan and click "Insert".

    The scan engine's name for your list (actually a number, so for instance, [favorites list is 15]), followed by your name for the scan (preceded by the comment symbol //), will show up as the LAST line of your scan. It might be out of view - scroll down until you see it.

    Cut and paste it back to the top of the scan.

    That should do it. Let me know.

    Another thought - you may be aware, but for others - when you run a scan against a list, the scan engine only looks at the symbols, not the time frame - so you could run both weekly and daily scans against the same list. If you want to save the results for the alternate time frame, you can put them in a separate (probably temporary) list and apply the appropriate style to verify the results.
  • markdmarkd mod
    edited April 2016 Answer ✓
    It's in the Industrials sector (XLI) and $DJUSHR - Commercial vehicles.

    $DJUSHR is an index but as far as I know, there is no ETF associated with that index - although I didn't research it.

    ( "Full Quote" gives you the names of the sectors and industries, but not the associated index/etf symbols.)

    If you include this Price or Price Performance ratio in your chart style, you will get the associated indexes and Sector SPDRs, if the symbol belongs to one.


    This shows the relative strength of the industry to its sector, which might be useful. On my charts (following Gatis Roze's idea, but not exactly) I have four RS lines placed behind one another (with a different color for each line). If you buy either momentum or the RS idea, the bottom two should both be above zero and have a generally positive slope, and even better (but later in the cycle, probably) if the top two are doing the same.


    Not sure if that's helpful - might be overkill for some.

    If you put "$DJUS" in the symbol search, you will get all the indexes (but not ETFs) that correspond to the members of the Sectors and Industries drop down.

  • markdmarkd mod
    edited April 2016 Answer ✓
    Hi @BobS ,

    I'm not sure I'm on the same page with you on this one:

    "1. I have considered using the SCTR ranking instead of this RS with the SPX. What do you think of the SCTR ranking, especially as a replacement for the RS with the SPX? "

    Are you referring to relative strength "RS" meaning a ratio between two symbols, like IBM:$SPX, or do you mean relative strength the indicator RSI(14)?

    If you are asking about using a SCTR score with $SPX in place of RSI(14), I don't believe you can. When I bring up $SPX in a chart style that includes the SCTR Line indicator, it displays a blank window and the legend says "SCTR - $SPX (undef)", which I take to mean that $SPX has no SCTR rank (what would you rank it against?).

    If you are asking, should you replace the Price Performance indicator $SYMBOL:$SPX with the SCTR Line indicator on your charts, you could. I have both on my charts. I haven't decided which I like better. The advantage with Price Performance is you can use it for any stock or index against a base symbol, like $SPX. With SCTR, not everything, especially the industry indexes, which I like a lot, has a SCTR ranking.

    "2. If you do like the Sctr, how would you write a scan to select only stocks with average vol > 1,000,000, with Sctr > 70 and with change in Sctr over the last week > 20."

    and [sma(21, volume) > 1,000,000]
    and [SCTR > 70]
    and [SCTR > 5 days ago SCTR + 20]

    The advantage of SCTR over RS (the Price Performance symbol ratio version) is that you can scan for it. It is similar to RS in that the ranking comes from a comparison of various technical measures across multiple symbols that have some kind of similarity. So by comparing the SCTRs of various stocks you can see which is performing better by the SCTR measures. I don't know if it is similar to RS in that a divergence between price and SCTR - e.g. price advances, SCTR does not, or vice versa, is a tradable signal as it can be for RS (ratio) and price.

    "3. How would you change the two numbers I chose for minimum Sctr (70) and minimum Sctr change (20)? "

    I haven't done the research to offer an opinion on this.
  • markdmarkd mod
    Answer ✓
    Hi @BobS ,

    I think SCTR.large and SCTR.small are sufficient, unless you want to limit your results to the specified groups.

    See this link for an update on SCTR memberships:

    It appears that ALL stocks with a SCTR ranking are listed here:

    Use the drop downs to see each SCTR sub-group.

    If you want to limit your results to the groups named above, you need to bracket your "or" statements:


    [group is DOW30]
    [group is SP100]
    [group is NASDAQ100]

    and [SCTR.large > 70] and [SCTR.large > 5 days ago SCTR.large + 20]

    You don't have to format it exactly that way - it's just to emphasize that the collection of
    "or" conditions should be evaluated as one condition. Without the brackets, you get everything that fits the last condition, - plus - ALL the stocks in each of those groups. But what you want is only stocks in those three groups that also fit the last condition.


  • @gord thank you for changing this to a question so I could give MarkD credit for answering it. I will try to remember to list my questions as questions in the future. Thanks for the directions to the notification preferences. When I went there, it already had me down to receive notifications by email for all of the options and to receive popups for all but one. Also, it has my correct email address. So, do you have any idea why I did not get a notification that my discussion had been answered either by MarkD or by you?
  • @Gord: Sorry I had not checked my email. I was incorrect. It DID notify me by email that you had answered my question. Based on that it seems quite reasonable that the software just gave priority to telling me that MarkD had mentioned me in a discussion rather than telling me that he had answered my question (or commented on my discussion.

    All is as it should be. Thanks again.
    It is good to be back.
  • @MarkD I must not have understood something you said regarding your scan to rank the symbols in a chartlist.
    1. In order to avoid the limit of running this only with an end date of the end of a week, I switched to daily charts rather than weekly.
    2. Then I put the daily charts for the SPDRs and a few other symbols along with $SPX into a chartlist and gave it the number 0099.
    3. I then chose to start with a period of 12 days for ROC, since that was the default time period.
    4. Then I ran the following simple scan which ran without error but found 0 results.
    // begin rank SPDR scan
    [favorites list is 0099] // where ?? is the number assigned to your favorites list
    rank by ROC(12)
    // rank by RSI(14)
    // end scan

    I was expecting the scan to result in a list of the symbols in the rank order for ROC(12). Was my expectation wrong or my implementation? Or were both incorrect?
  • Yes, that did it. Thanks. I have one other question that the results of these scans has raised. To what group (index or ETF) does MTW belong? I could not find it using the Sector Summary and drilling down.
  • Yes, that was helpful. Thanks for not only giving me the fish but teaching me to fish as well. I have incorporated these 4 RS lines on a panel of my main weekly chart style. That is precious real estate. I already had a version of SYMBOL:$SPX behind another indicator. Now the 4 RS lines (in different colors) have their own panel. Thanks. I think this will help me spot symbols that should become my next purchases.
  • Hi @BobS, you probably already know, but for others, depending on the indicator, you can compress some of your window Height settings to .02 or .03 without losing legibility. That leaves more chart space open for price.
  • Thanks @markD. Good suggestion. Yes, I make most of my indicator windows 0.2 in height.
  • @MarkD Thanks again for your help on these scans for Relative Strength of stocks in my favorites list to the SPX. I have 3 related questions.

    1. I have considered using the SCTR ranking instead of this RS with the SPX. What do you think of the SCTR ranking, especially as a replacement for the RS with the SPX?
    2. If you do like the Sctr, how would you write a scan to select only stocks with average vol > 1,000,000, with Sctr > 70 and with change in Sctr over the last week > 20.
    3. How would you change the two numbers I chose for minimum Sctr (70) and minimum Sctr change (20)?

    Thank you so much.

  • @MarkD Thanks. That is what I needed. Sorry for being vague with the term Relative Strength. By that I meant to say "Price Performance" rather than RSI. Your answer helped a lot. Thanks for the scan. I am doing the research but do not have a lot to report as yet. Thanks again.
  • @Markd - If I wanted to scan for good SCTRs only among Large Caps, should I use the following lines in the scan?
    and [group is DOW30] or [group is SP100] or [group is NASDAQ100]
    and [SCTR.large > 70] and [SCTR.large > 5 days ago SCTR.large + 20]

    Similarly, would I use the following for scanning for good SCTRS among small caps?
    and [group is SP600]
    and [SCTR.small > 70] and [SCTR.small > 5 days ago SCTR.small + 20]
  • Thank you for this answer and especially for your guidance on using brackets to combine the 3 groups of large caps. Thanks also for your statement "I think SCTR.large and SCTR.small are sufficient, unless you want to limit your results to the specified groups". By this statement do you mean that if I use SCTR in the scan of the Dow30 + SP100 + Nasdaq100, the software will compute the SCTRs in comparison with the 230 stocks of the Dow30 + SP100 + Nasdaq100 rather than in comparison with a much larger group if SCTR.large is used?
  • Hi @BobS , no, the SCTRs will be calculated according to their SCTR group (.large), regardless of their membership in the other groups. But your results will include only those .large stocks that are also in the Dow, SP100 or NASDAQ100. If a .large stock fits the >70 and +20 condition, but is not in one of those groups, it won't be in your result.
  • Thanks @markd. And thanks again for the brackets advice. I can't believe that I did not bracket those initially. But I now think I am getting a basic grasp of the scan engine.
Sign In or Register to comment.