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 setup questions...

Hi All, I am testing the stock charts scanner to see if it fits my needs. Couple of things I am having trouble with getting the syntax correct..
1. One parameter I want, amongst many others, is a rising 200 Dma. I can't seem to find the right syntax to make this requirement show through on my scans. Any help would be greatly appreciated!
2. I also want the current price to be within 10% of 52-week highs. Again, I need the correct syntax. Everything I am trying is not working.

I look forward to learning from you Stockcharts scanning experts!


  • markdmarkd mod
    edited November 2019
    You need to compare the MA today to the same MA some number of bars before today, and today's value should be greater than the previous value.

    The value of the sma today is

    sma(200, close)

    The value of the past bar could be something like

    21 days ago sma(200, close) // or some other value, 10 days ago, 50 days ago

    And you would compare them using a comparison operator, in this case greater than, which is ">". And you need to put the whole comparison statement between a pair of brackets [ ]. Look at some sample scans for examples.

    Scan documentation is here:

    For "within 10% of 52 week high", you need to compare the current price to fractional multiples of the 52 week high.

    The 52 week high is

    weekly max(52, weekly close) // or, you could use high instead of close.

    or, if you want to keep everything in the daily time frame (good idea):

    max(251, close) // 251 trading days in most years, sometimes 252 or 253 depending where holidays land.

    Fractions, or per cents, of a value are expressed with decimals. So, "within 10%" is between .9 and 1.1 times the max value(100% is 1.0, ten per cent is .1, so 1.0 - .1 = .9 and 1.0 + .1 = 1.1. So, you want the price (meaning today's close) to be greater than

    max(251,close) * .9

    and less than

    max(251,close) * 1.1

    That requires TWO statements, one for less than, one for greater than.

    If you get stuck, post what you have.

  • Great info! I will give it a try and get back to you. Many Thanks!
  • All that great information worked! Thanks again!
  • Just a short comment: you like others getting started with scanning had a question regarding syntax - but really, the obstacle isn't syntax (which is really just punctuation and order of terms), but how to think about what you want.

    Many people think scanning is hard because it's programming and they don't know how to program. But it's not the syntax that is really so challenging. You can easily pick up most of it just by looking at the examples.

    Most of the time, what you really need is to find a way to restate your requirements using the terms and operators available in the scan engine -many of which most people have seen before. For instance, above and below (this one is obvious) really mean greater than or less than. So if you say you want to scan for the current price above the MA, then you want a "close" greater than ">" the MA "sma(200,close)".

    Something like "rising" takes a little more thought. There is no "rising operator", so you have to think of something that is true about a stock (or an MA, or an indicator) that is rising. In other words, you have to come up with a definition by using the scan engines terms and operators. If somebody asked you, what is a summer day, you might say a day between June and September that is long and hot. So if you some one asks you, what does rising mean, you would say something that was lower before and is higher now - and then figure out how to say that with scan terms and operators (today's close > 5 days ago close). Likewise with "within". What does "within" mean - it means greater than one thing and less than another thing.

    So the trick with scanning is to re-think those things we know intuitively and get into the details of what we already know but don't think about anymore. And, of course, getting familiar with the terms and operators available by reviewing a little bit of Chart School every day, or maybe every weekend, until you are pretty familiar with what's available.

  • Thank you for that explanation Mark! I appreciate it.

    I have been trying to apply what you said to another scanning issue I'm having, but just not getting what I want.

    Here's my issue-- Amongst all the scan criteria I already have, I want to add "price crossed and closed above 50dma" OR "closing price is within XX% of 50dma". My goal is to get scan results showing stocks that have the potential to bounce off 50dma (or whatever MA I choose). In other words, I want stocks that are trading very close to the 50 dma to add to my watchlist.

  • markdmarkd mod
    edited December 2019
    Well, for crossing over situations, there IS an operator - "x". The term on the left crosses above the term on the right. You also have define more specifically you mean by price - there are several - high, low, open and close. You can select any one of those from the appropriate drop down on the scan workbench page. The MA is either an ema( ) - exponential, or sma( ), simple. So reframe your thinking using all of those terms instead of "price" and "dma".

    As for the per cent issue, the answers above tell you how to get a value (like close) "within" a certain per cent of another value ( like an sma). The first value is less than some per cent (greater than 1, like 1.1) of the second value, and greater than some other percent (less than 1, like .9) of the second value.

    If you get stuck, post what you have.
  • That worked! Thanks so much for your assistance. Using the "x" operator got the results I wanted. Happy Holidays!
  • Hi Again! Another scanning question for you. I am hitting a roadblock trying to tweak my scan slightly to yield better results. I am attempting to scan for stocks that, in addition to my previously entered criteria, have traded INSIDE the range of the previous day's range, for the past two days. AND the stock closed higher three days ago than it closed 4 days ago.

    Here is what I have...

    and [0 day ago range < 1 days ago range]
    and [1 day ago range < 2 days ago range]
    and [2 day ago close > 3 days ago close]

    With the above I am NOT getting- inside bars the past two days after a positive close three days ago - like I want. Do I need a different operator beside >, < ? "Inside" isn't recognized.

    Here is a pic of the setup I am attempting to bring back with my scan...


    Thank You!
  • I don't use Range so not conversant in it's use. How about

    // High is lower or equal to the prior day

    High <= 1 day ago High
    I day ago High <= 2 days ago High

    //Reverse it for lows
    //Low is higher or equal to the prior day

    Low >= 1 day ago Low
    1 day ago Low >= 2 days ago Low

  • "range" returns a numeric value (to the scan engine, not on the results page (unless you use rank by range)), which is the difference between high and low. So these statements are equivalent:

    and [range > 3]

    and [high - low > 3]

    lmkwin is correct, if you want to know whether today's bar overlapped a previous bar, you have to directly compare data points from the two bars - high to high, and/or high to low, high to open, high to close, low to high, low to low, etc.

    So, for instance, an "inside" day, where today's range is completely inside yesterday's range would look like this:

    and [high < 1 day ago high]
    and [low > 1 day ago low]

    Your patterns can get as complex as you want, provided you keep track of the offsets (1 day ago, 2 days ago, etc.) and the data points you are comparing (high to high, high to open, close to low, etc.).
  • Awesome info Imkwin and Markd. Thank you so much!
Sign In or Register to comment.