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.

scanning for 4 out of the last 5 days

If I wanted to scan for a list of stocks where the price rose yesterday AND volume has risen for 4 out of the last 5 days how would I do that? I tried stringing together a set of and/or statements but I couldn't ever get it to work. So I think something is wrong with how I am coupling them. I understand I would get a large list if this were the only thing in the scan, this is a portion of the query I can't figure out. Any help would be appreciated.

Best Answer

  • markdmarkd mod
    edited June 2015 Accepted Answer
    You would have to figure out all possible combinations of up and down days and group them will "or" statements. The trick with or statements is to watch your brackets. In this case, put double brackets around the five volume relationship statements - so they are treated as one statement; then another set of brackets around ALL the volume relationship statements, so the sequence of "or" conditions is also treated as one statement.

    So it would look like this:

    // universe of stocks
    [group is sp500]

    and

    [

    // 4 days ago is lower volume (today is first day, so "four days ago" is fifth day)
    [[4 days ago volume < 5 days ago volume]
    and [3 days ago volume > 4 days ago volume]
    and [2 days ago volume > 3 days ago volume]
    and [1 day ago volume > 2 days ago volume]
    and [volume > 1 day ago volume]]

    or

    // 3 days ago is lower volume
    [[4 days ago volume > 5 days ago volume]
    and [3 days ago volume < 4 days ago volume]
    and [2 days ago volume > 3 days ago volume]
    and [1 day ago volume > 2 days ago volume]
    and [volume > 1 day ago volume]]

    or

    // 2 days ago is lower volume
    [[4 days ago volume > 5 days ago volume]
    and [3 days ago volume > 4 days ago volume]
    and [2 days ago volume < 3 days ago volume]
    and [1 day ago volume > 2 days ago volume]
    and [volume > 1 day ago volume]]

    or

    // 1 day ago is lower volume
    [[4 days ago volume > 5 days ago volume]
    and [3 days ago volume > 4 days ago volume]
    and [2 days ago volume > 3 days ago volume]
    and [1 day ago volume < 2 days ago volume]
    and [volume > 1 day ago volume]]

    or

    // today (day 1 of 5 days) is lower volume
    [[4 days ago volume < 5 days ago volume]
    and [3 days ago volume > 4 days ago volume]
    and [2 days ago volume > 3 days ago volume]
    and [1 day ago volume > 2 days ago volume]
    and [volume < 1 day ago volume]]
    edit should read "and [volume > 1 day ago volume]]
    ]


Answers

  • Thanks markd. I think I tried that combination, but I can't be certain of it because I was bleary eyed by the time I gave up last night. It's funny how you and I even labeled each grouping almost identically. Great minds think alike indeed!! It is possible I might not have done the extra bracket around each grouping though, so there is hope my friend! I will let you know if it works for me. I kept getting results where I know a stock met the criteria but it wasn't showing up.
  • markdmarkd mod
    edited June 2015
    You probably know to do this, but if you know the missing stock matches the volume criteria, double check that it meets all other "universe" criteria you might have, like membership in a group or list or industry, or market cap, or SCTR rank, etc. Some to these can change unexpectedly.
  • Thanks again Mark. The scan works fine now. I was leaving off the very first bracket in the chained and/or sequence and the very last bracket.
  • In case you use this for anything the last group has an error in it. There are two days that have lower volume out of the group.
  • Good catch. Sorry about that.
  • gordgord admin
    Great explanation markd, I was trying to find a simpler way but kept coming back to the same method you described. These types of scans are some of the most difficult and lengthy to code as the scan engine was never designed to look for the random 1 out of 5 type scenarios.
  • @gord Agree. I love the scan engine, though. It is remarkably flexible. There are a few things I would like it to do that it can't (like determine whether the max volume in the last x days occurred on an up close or a down close). What I've found though, is that the market itself has many ways to accomplish the same thing (make a low or a high, break out or break down, etc.), so that the real challenge in writing an effective scan is to find the right balance between abstraction and specificity. It seems you will always pick up some trash or miss some gems. But you should still be able to do well with what you do find.
  • Amibroker is another good tool for scanning that is about as robust as a program can get. The problem for me is I am not good with coding. Maybe I need to hire a college kid or something :-) You guys (gord included, I've found your posts to be helpful too) are great and extremely helpful.
Sign In or Register to comment.