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

It could change of course but the scan below has not selected RUT all morning long even though RUT meets all of the requirements, I think. Can anyone see what is wrong with this part of the scan? The second paragraph.

[Favorites list is 10] and [1 Day ago MACD HIst(6,9,0) > 0.0] and [Full Stoch %K(14,3,3) < 1 Day ago Full Stoch %K(14,3,3)] and [[[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]

or [[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]

Comments

  • You have an extra (or else a missing) bracket - it doesn't pass syntax.

    Also, in the first line you have 1 day ago MACD Hist(6,9,0) - is that intentional, or a typo?

    I've already expressed my opinion on mixing time frames, so I won't bother you with that again. But given that, I don't see the value in spending as much time as it would take to figure out what's going on with the logic.
  • Thanks again. There is a missing bracket above because the complete scan is massively large so I didn't include the whole thing. Yes, I do intend 1 Day ago MACD Hist(6,9,0). That histogram represents the 6ema and 9ema from yesterday. It's easier for me to see visually on the chart and it takes up less space in a scan. In the above portion of the scan, one should add one bracket at the very end before running the scan for testing. My apologies, I should have included it before asking the question.
  • This will pass syntax

    [Favorites list is 10] and [1 Day ago MACD HIst(6,9,0) > 0.0] and [Full Stoch %K(14,3,3) < 1 Day ago Full Stoch %K(14,3,3)] and [[[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]

    or [[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]]
  • Below is another way to express the same scan above. I am testing it. It did select RUT this all morning long until price rose high enough to raise the weekly macd line above last Friday's weekly macd line.

    [Favorites list is 10] and [1 Day ago MACD HIst(6,9,0) > 0.0] and [Full Stoch %K(14,3,3) < 1 Day ago Full Stoch %K(14,3,3)] and [[[MACD Hist(48,104,0) > 0.0] and [MACD Hist(48,104,36) > 0.0] and [MACD Hist(48,104,0) < 1 Day ago MACD Hist(48,104,0)] and [Today's MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]

    or [[MACD Hist(48,104,0) > 0.0] and [MACD Hist(48,104,36) > 0.0] and [MACD Hist(48,104,0) < 1 Day ago MACD Hist(48,104,0)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)]]]
  • This is my first time on here, and my first question... How do you write a scan aimed at a specific sector or industry?
  • Since this is such a basic question, I think it would be helpful to start at the beginning, which is here:

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

    The answer to your specific question would be found under this link on the page above:

    http://stockcharts.com/docs/doku.php?id=scans:advanced_scan_workbench

    Writing scans is not that hard, but you do have to master the basics first, which are the advanced scan workbench and the scan language syntax.

    Here's a quick and dirty summary of the basic rules of the language:

    Basic rules for the scan engine:

    Every statement begins with “and” except the first one.

    Every statement, except the word “and”, goes between square brackets [ ].

    NOTE: Parentheses " ( " and " ) " are reserved for indicators and functions, like RSI(14) or max(10,close). If you need to group arithmetic expressions, use more square brackets, not parentheses: For instance:
    And [ [high – close]/max(10, close) > 10]

    Every statement contains an operator. Valid operator are: is, is not, >, <, =, !=, >=, <=, x, contains, not contains.” !=” means “not equal to”. “x” means “crosses above”.

    Every statement has one value preceding the operator and one value after the operator.

    Values can be indicators, overlays, numbers, reserved words like group, market cap, close, etc. (see drop downs on Advanced Scan page) or expressions using these values.

    Some examples:
    [group is SP500] // note: this would be a first scan statement because it doesn’t begin with “and”
    And [MACD Line(12,26,9] > 20]
    And [MACD Line(12,26,9) x MACD Signal(12,26,9)]

    You can also write “or” statements. “Or” statements need to be isolated with an extra set of brackets.

    // begin scan
    [group is sp500]
    // get bullish and bearish crossovers
    And
    [
    [ MACD Signal (12,26,9) x 20]
    Or
    [ 80 x MACD Signal(12,26,9)]
    ]
    // end scan

    The double slashes "//" tell the scan engine to ignore everything on that same line that comes after the "//". So you can use that space to explain to yourself (for later) what you thought you were trying to do in the scan code.

    NOTES on scan logic with “and” and “or”:

    If a scan has ONLY “and” statements, all the “and” statements must be true for the scan to return a symbol.

    If a scan has ONLY “or” statements, then only one condition must be true to return a symbol.

    If a scan has a mix of “and” and “or” statements, the results depend on whether you isolated the “or” statement with extra brackets as shown above:

    If you don’t use the brackets, then only one condition in the entire scan has to be true to return a symbol.

    If you do use brackets, then every “and” condition must be true AND at least one “or” condition must be true to return a symbol.


    Start simple. It's actually harder to figure out WHAT to code than HOW to code.

    For instance, how would you code for a rising SMA 200?

    You need to think about what would be true if the SMA 200 really is rising. First thought - the value today would be different from the value yesterday, or maybe 10 days ago or 100 days ago.
    And it would be greater because it is rising. So the scan would compare today's SMA 200 to the past SMA 200 and it would be greater, so:

    and [sma(200,close) > 10 days ago sma(200, close)]
  • Can I ask, is SMA(200) > 10 Day ago SMA(200) the same as SMA(200,close) > 10 days ago SMA(200,close)? I mean will they produce the same results?
  • I think the default for the sma function is "close", so yes, they should be the same. But, for clarity, it's better to include the word "close" so you don't have to remember or wonder. But that's up to you.
  • Well, I wondered if using the word close would force the scan to work only at EOD and would not work well during the day?
  • markdmarkd mod
    edited August 2018
    That seems very unlikely and as far as I know, there is no documentation of an effect like that.

    Intraday, the most recent update is the "close". Since the data at each update is likely to be at least slightly different, you are likely to get different results from different updates.

    If you don't get different results when the data has changed, then it's possible there is a protocol limiting the frequency intraday scans once the scan has delivered a hit. . It seems that is how the alerts are managed. That would make sense as a way to manage the scan engine's capacity. I don't know that for a fact, however.

  • Thanks again.
  • In case your interested, the MACD settings below seem to be very close to the weekly MACD fast line and signal lines with regard to scan results. So far, they produce almost identical results. Maybe using them instead of mixing daily and weekly criteria in a scan will be better somehow. Anyway, it's not exactly the same but it's so close that it's almost impossible to tell the difference.


    [MACD Hist(48,104,0) > 0.0] and [MACD Hist(48,104,36) > 0.0]
  • Sounds promising. I hope it works out for you.
  • Mark, if you get this in time today, can you see why this one is not choosing SPX yet?

    [Favorites list is 10] and [Open > Close] and [1 Day ago MACD HIst(6,9,0) > 0.0] and [Full Stoch %K(14,3,3) < 1 Day ago Full Stoch %K(14,3,3)] and [Full Stoch %K(14,3,3) < Full Stoch %D(14,3,3)] and [[[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)] and [EMA(5) < EMA(8)]]

    or [[This week's MACD Line(12,26,9) > 0.0] and [This week's MACD Line(12,26,9) > This week's MACD Signal(12,26,9)] and [This week's MACD Line(12,26,9) < Last week's MACD Line(12,26,9)] and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)] and [MACD Line(12,26,9) < 1 Day ago MACD Line(12,26,9)] and [EMA(5) < EMA(8)]]
  • I left out one right handed bracket at the very end of this, sorry
  • Just too complicated for me to spend time on, especially with the mixed time frames. Sorry.
Sign In or Register to comment.