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.

Defining a consolidation, a dip below, then back up in the consolidation

I'm trying to build a scan that will catch a price where it's near but above the 52-week low. I'm looking for symbols that have consolidated near their lows, have dropped below the consolidation but then got back up on top of that earlier consolidation (e.g., GDX around the 15th to the 25th of January, where it dipped below the low for the last over a year, then got back up in the old consolidation area before heading on up).

When I ran what I have below, one of the charts (HRB) showed the last two days below any previous low for more than a year. That certainly obeys the last clause, but shouldn't the first clause keep it from including anything lower than 1% above the 52-week low? My thinking for these two clauses is that the first would keep today's close in that range near the low for the last year, and the second would keep it above the low, perhaps back up on top the low of the consolidation below the yearly low.

[[today's low < yesterday's min(260,low) * 1.02] and [today's low > yesterday's min(260,low) * 1.01]]
and [today's close > yesterday's min(5,low)

Comments

  • markdmarkd ✭✭✭
    edited March 2016
    If you run it when the market is open and specify the scan start date as the (default) last intraday update (see the Starting 0 trading days before" window), which is during the day today March 5, yesterday's HRB low is included in the scan data - it would be "yesterday's min(260,low)" because the scan engine takes the latest intraday update as "today's" close.

    If you change the default and set the scan start date to "Last market close (Mar 4)" (look in the drop down), the scan engine ignores data generated during the day today, so HRB's low from (calendar) yesterday is "today's" low, so HRB doesn't appear in the results.

    I remember tripping over this, too, a few years back. Maddening. I haven't checked the documentation to see if this wrinkle is mentioned now.
  • Thanks for your help. I'm enjoying learning to write these scans, but it is a bit frustrating. My only other coding experience is the programming in BASIC class back in college in 1981.

    I ran the scan after the market closed, and also set the start date to Last market close (Mar. 7) in the drop down to make sure. I still catch HRB (only one low below today's close) in it, as well as a few others that don't conform. I'm attaching a screenshot with one that conformed (lows below today's close marked with a star), one that only four of the five that did (odd man out circled), and the HRB that has only one low below today's close. Shouldn't the first clause be excluding it completely since there's only two candles in that island that gapped so far below the low just two days ago?

    I do see other things that I need to do in the scan to get what I'm looking for, but if that last line doesn't work, the rest of my idea isn't going to either.
  • Update: I also added brackets to enclose the whole of [yesterday's min(260,low) * 1.01] to make sure it was applying the multiplier to the last 260 lows. It took out some of the list, including HBR. I still got CNL, which has the one low in the last five that was above the last low.
  • markdmarkd ✭✭✭
    Well, I think I see the problem better - you want no lows above today's close.

    But, this condition

    and [today's close > yesterday's min(5, low)]

    requires only ONE low below today's close. It does not say you can't have lows above today's close. It just says, you want the lowest low, whichever one that is, to be lower than today's close.

    But, if I understand you correctly, you really want ALL the lows lower than today's close. In other words, the highest low is lower than today's close - so:

    and [today's close > yesterday's max(5,low)]

    That says, no low in the last 5 bars (starting yesterday) was greater than today's close.

    Your syntax as posted above is fine - except you have an extra pair of brackets in the first line - you don't need to group those statements, although, in this case, there is no harm if you do.
  • snyderk5snyderk5
    edited March 2016
    Excellent. I have more to do on the scan, but that tweak will be very helpful. Thanks!
  • A couple more questions:

    I want to just limit the scan to the lower x% of the 52-week range. This line doesn't pass the syntax test:

    and [today's close < (yesterday's high(253,low*0.1)]

    It looks like it doesn't like a space ("") in it, but I don't see what is the problem. My intention is for it to limit the scan to the lowest 10% of the range.

    The other question is about the difference between the two arguments [today's close > yesterday's min(5, low)] and [today's close > yesterday's max(5,low)]. I don't understand why min would make it require only one of the previous 5 days' low to be lower than today's, but max would require all 5 days' lows to be lower. How is the scanner interpreting those terms? Thanks.
  • markdmarkd ✭✭✭
    edited April 2016
    I'll answer the second question first. An example should help:

    Suppose the last five lows are:

    21 23 20 19 22

    The minimum value is 19.
    The maximum value is 23.

    So:

    If today's close is 20, close > min(5, low) is true, because 20 > 19
    If today's close is 20, close > max(5, low) is false, because 20 < 23
    If today's close is 24, both statements are true because 24 > 19, and 24 > 23.
    If today's close is 18, both statements are false because 18 < 19 and 18 < 24.

    Now your scan condition:

    Here's your line:

    and [today's close < (yesterday's high(253,low*0.1)]

    There is no function called "high( )" (good guess, though), so the scan engine would reject that. Unfortunately, you can't pick functions from the the drop downs, so you just have to know them. Here's a link to the support page that explains them (although it could explain a them little more with an actual example):

    https://stockcharts.com/docs/doku.php?id=scans:functions

    So you are looking for a close in the lowest 10 per cent of the 52 week range. This is a little complicated because to get the 52 week range you have to write something that picks out the highest high and the lowest low in the last 52 weeks - or, in the daily time frame, 253 days as you have defined it.

    So, the highest high in the last 253 days is "max(253, high)".

    The lowest low in the last 253 days is "min(253, low)".

    Now we need the range, which is the difference between the max high and the max low, so we have to subtract the low from the high. It's best to put arithmetic operation like that in brackets, so:

    [ max(253, high) - min(253, low) ]

    So that's the 52 week range. If the high were 50 and low were 30, that phrase would produce the number 20.

    Now we want 10 per cent of the range. So, we would multiply the range by .1, as you had in your scan - use another set of brackets for that operation:

    [ [max(253, high) - min(253, low)] * 0.1 ]

    Using the example high and low, 50 and 30, that will resolve to the number 2, as 10 per cent of 20 is 2.

    Now comes the tricky part - you want the close to be less than 10 per cent above the 52 week low.

    So how do we write 10 per cent above the 52 week low?

    We know how to write the 52 week low because we did it above:

    min(253, low)

    And we know how to write 10 per cent of the 52 week range because we did it above:

    [ [max(253, high) - min(253, low)] * 0.1 ]

    So, putting those two things, together, 10 per cent above the 52 week low is:

    [min(253, low) + [ [max(253, high) - min(253, low)] * 0.1 ] ]

    Now we want today's close to be less than that number, so the final scan line will be:

    // close less than 52 week low plus 10 per cent of 52 week range
    and [today's close < [min(253, low) + [ [max(253, high) - min(253, low)] * 0.1 ] ] ]

    Let me know if that all makes sense. Watch your brackets.
  • The test I just ran combining the "max" and the "lowest 10%" are successful. So to translate the min/max statements into prose, would it be accurate to think of them in this way:

    for min: "today's close is greater (higher) than the lowest low (minimum) of the last 5 candles' lows," and
    for max: "today's close is greater (higher) than the highest low (maximum) of the last 5 candles' lows"?

    I still have a few more refinements to try to add, but this has gotten me so much close to my goal, and has been very helpful toward understanding how to compose the statements. Thanks so much!
  • markdmarkd ✭✭✭
    Your prose statements for min and max are correct. Glad those answers were helpful. Way to hang in there, bro! That's how it's done.
  • markdmarkd ✭✭✭
    edited December 2016
    I just noticed there is an error in one of my answers above:

    " Unfortunately, you can't pick functions from the the drop downs, so you just have to know them. "

    That is incorrect. You can find max, min, absval, PctDiff, PctChange, sma, ema and kama under the "Technical Indicators" drop down. They make up the first grouping at the top of the drop down list.

    SMA, EMA and KAMA are explained in Chart School.

    This support link explains the others:

    https://stockcharts.com/docs/doku.php?id=scans:functions
  • Cool. I'll take a look. I have been gathering a few more ideas for scans, and hope to work on them later in January after my winter vacation. The one I have that you helped on earlier this year has worked amazingly well for me. Thanks!
Sign In or Register to comment.