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.

Using Mathematical Expressions in Scan

Is there a way to scan for something like this:
[(OPEN - CLOSE) <= (HIGH-LOW)*1.5]
or scan for absolute value like:

Best Answer

  • markdmarkd mod
    edited October 2015 Answer ✓
    You are still using parentheses around "high - low".

    "high - low" is not a function, so you have to use brackets:

    [high - low]


    (high - low)

    If you look closely at the last two scan statements in my previous answer, you will see that it uses brackets everywhere except for absval(open-close).

    if you like, you could cut and paste those two lines into the advanced scan window and press check syntax and run it.


  • The ABS( ) expression needs parentheses but you have to use brackets instead of parentheses for the other expressions, e.g. [high - low] instead of (high - low), to get past the syntax check.

    You also need brackets to enclose the entire statement

    and [... ]

    so you will have sets of brackets for expressions inside brackets to enclose the entire statement.
  • Thanks for your (quick) reply Mark,

    When I write : [ABS [Open - Close] <= [High-Low]*1.5]
    I get the following: Could not parse "ABS [OPEN - CLOSE]"

    I tried using regular parenthesis (...) to open and close the argument, but it didn't work.

    What am I missing?
  • markdmarkd mod
    edited October 2015
    The correct function is absval( ), not abs( ). Sorry I didn't catch that.

    This passes syntax:

    and [absval(open - close) >0]

    I'm wondering about your full statement, though.

    The distance between the open and close can never be greater than the distance from high to low (in the same bar), but you seem to be asking for cases where open to close is less than an even larger distance - 1.5 x the distance from high to low.

    For instance, this returns all 500 of the SP500:

    [group is sp500]
    and [absval(open - close) <= [high - low] * 1.5]

    Are you looking for open to close to be some proportion of the total range?
  • You are correct, the first part works, but I still get an error message when I add the second part of the equation:

    [ABSVAL(Open - Close) <= (High-Low) * 1.5]

    I modified it like this:
    [ABSVAL ((Open - Close) <= (High-Low)) * 1.5]

    or with brackets:
    [ABSVAL [(Open - Close) <= (High-Low)] * 1.5]

    Still doesn't work...
  • Thank you Mark for your "always" judicious comment!

    Indeed, I had the wrong brackets-parenthesis in the formula. I corrected it and it worked.
    And, you are correct about "The distance between the open and close can never be greater than the distance from high to low..."

    My original scan contains more data than what I asked here. I was struggling with the math data scanning, and you resolved it brilliantly! After all, I can't divulge all my little secrets on how to find the right stock at the right time!
  • Understood! :) Glad you got it worked out!
Sign In or Register to comment.