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 with CHART, Gap Scan, please!

samca298samca298
edited April 2016 in Scanning
Hi,

I'm trying to create a scan that finds a stock that gap up 6 days ago over 10% from the previous day. Then essentially traded within a 3% range of that 6th day high day for the next 6 days. So basically looks for a tight 6 day flag from a previous gap over
10%. Also, can you please help include the criteria to show the stock above it's 9 ema

type = stock]
and
[country = us]
and
[6 day's ago low > 7 day's ago high * 1.10]
and
[3 days ago high < 4 days ago high * 1.03]
and
[daily volume > 400000]

Best Answer

  • markdmarkd mod
    edited April 2016 Answer ✓
    Hi @samca298

    What you have -

    [SMA(20, close) > 15]

    would pick out stocks where the moving average of the close is greater than 15. It doesn't say where the current close is - above, below or equal to the moving average.

    If you want stocks where the close is above its moving average, you would write:

    // close is above its 20 day moving average

    and [close > sma(20, close)]

    So there are two different terms you need to compare to each other, but you have to be careful about identifying which two you want to compare.

    The first one is the close - that would be today's closing price - and you write that with just the term "close". You don't know what that value is going to be from day to day, so you don't specify a specific value like 15, you use a "variable" called "close" which always refers to the last price (just like "high" always refers to the highest price, whatever it is from day to day, "low" to the lowest price, etc.)

    The second term is the moving average of the close. You need to use a built in indicator to express that, customized the way you want it.

    So the "general form" of the simple moving average indicator is sma(some number of periods, some value).

    We want the 20 period moving average of the close, so that's

    "sma(20, close)"

    The scan engine sees that term, gets the data (the last twenty closes) and calculates a value and substitutes it for what you wrote - so sma(20,close) becomes, let's say 17.23.

    If the close is 18.04, then the scan engine reads this line -

    and [close > sma(20, close)]

    as

    18.04 > 17.23

    That statement is true, so it selects that symbol for your results list (provided all the other conditions in your scan are true for that symbol also).


    If you wanted the simple moving average for some other period, or some other value, you might write

    and [volume > sma(63,volume)]

    and so on.

    You could write something like

    and [close > sma(63, volume)]

    That would be syntactically correct (the scan engine could find values for both terms), but it doesn't make sense because it compare apples (a price) to oranges (volume).





Answers

  • Your syntax seems to be fine, so it's just working out how to express the concept more clearly.

    I'm guessing you mean by 3% range, not more than 1.5 % above and not less than 1.5 % below (.015+.015 = .03).

    So the minimum (lowest) six day low must be greater than the 6 days ago high * .985 (1-.015)

    and the maximum (highest) six day high must less than the 6 days ago high *1.015

    Use the min() function to find the lowest low in the last six days, and the max() function to get the highest six day high.

    If you get stuck, post what you tried.
  • For the sma, you can select sma from the Technical Indicators drop down on the Advanced Scan page and edit it for 9 and close (instead of 50 and volume). Then you want the close to be greater than that, so just compare them close > sma.
  • Mark - Is this what you mean for the moving average? It doesn't seem to show stocks over their 20 SMA.

    [SMA(20, close) > 15]

    Please advise.
    Thanks
  • Thanks Mark - That helped a lot. These stuff is confusing for non tech guys. Stockcharts should really offer more support
  • Hi @samca298 , I agree it's not easy at first if you don't have programming experience. But in Stockchart's defense, it's almost impossible to anticipate what kinds of support thousands of different people will need. And support is expensive. Putting up this "self-help" site was a great idea and it seems to working pretty well. I'd like to see more participation, but maybe that will happen with time. They are improving documentation all time and the videos are helpful, too, if you haven't had time to review them.
  • Agreed - I'm hoping you can help a little more. Once I get a few of these down, I'll be able to use what I've already created to move forward. I understand the EMA now.

    But I'd appreciate help with minimum/maximum.

    So like you stated, yes not more than 1.5% higher and 1.5% lower. Can you please help me to edit this? I want to be able to create a flag type of scan. So the stock gapped up 6 days ago and closed 10% higher and then traded within a narrow range for 3 days (or I can easily edit days for 4,5,6 etc)....

    [type = stock]
    and
    [country = us]
    and
    [6 day's ago low > 7 day's ago high * 1.10]
    and
    [3 days ago high < 4 days ago high * 1.03]
    and
    [daily volume > 400000]
  • So, in general, putting a scan together is a matter of defining all your elements, one by one, expressing them in scan engine speak, then figuring out how to compare the elements to get the conditions you want.

    So the starting point is the gap.

    A gap occurs when the low of the second bar is above, or greater than, the high of the preceding bar.

    So if we want to know if there was a gap today:

    and [low > 1 day ago high]

    Next we want to know if today's close is more than 10 % above yesterday's close.

    and [close > 1 day ago close * 1.10]

    Now you want to adjust those two statements so they look for the same situation some number of days ago. So I'll let you modify them with the "days ago" edits to get what you want.

    Now we want to know if prices have been within a certain range for a certain period of time.

    The width of a range is difference between the highest high and lowest low over some number of bars. But we only want situations where the highest high is within some per cent of the close some number of days ago. So we need an expression for the upper limit and an expression for the lower limit.

    For your situation, the upper limit of the range has to be:

    x days ago close * 1.015

    You wanted six days ago, so "x" would be "6".

    And the lower limit would be

    x days ago close * .985

    Now we need to test all the highs since the close against the upper limit.

    We need an expression for the highest (max) high over the last "x-1" days. We have to use x-1 because we do NOT want to test the high (or low) from the same bar as the close because a gap up bar normally has a pretty wide range outside the limit we want.

    (So for your case, x-1 would be 6-1 = 5)

    So in scan engine speak, we would express the high for the last x-1 days as

    max(x-1,high)

    In the same way, the low would be

    min(x-1,low)

    So now we have an expression for the highest high in our range

    max(x-1,high)

    and we have an expression for the high side limit of that range

    x days ago close * 1.015

    We want the highest high to be less than - "<" -the high side limit, so I will let you build that statement.

    // test actual highest high in range against high limit

    and [ ... ]

    Then you want to do the same thing for the lowest low in the range and the low side limit (min low > low limit).



    If you run into trouble, let me know.



  • Mark - I appreciate your help greatly./

    Can you please tell me if I wrote the below correctly

    [close < .985 *max (5,high)]

    I want to find a stock that has closed 1.5% below it's 5 day high. Is that how the above reads?

    Thanks
    Sam
  • Yes. But to clarify a little - that line will get any symbol that has closed AT LEAST 1.5 % below it 5 day high. So it would pick up symbols 2% or 10% etc. below. If that's what you want it's OK as is (except you need an "and" in front of it if it is not the first line in the scan).

    If you want a range, say less than 1.5 but not more than 2 % below, you need another line

    // begin scan
    // define stocks to look at
    [group is sp500]

    // find close between 1.5 and 2 percent below 5 day high

    and [close < .985 *max (5,high)]
    and [close > .98 * max(5, high)]

    // end scan
Sign In or Register to comment.