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.

Dividing a range by less than 2

Hello, I do have another question please. [Close < [[1 Day ago High + 1 Day ago Low] / 2.0]] is asking for something less than half of the previous day's range high to low. I would like to look at even less than half of the previous day's range but when I try to divide by 3 instead of by 2, I get nothing. [Close < [[1 Day ago High + 1 Day ago Low] / 3.0]] this does not work for me at all. Can you help ?

Comments

  • markdmarkd mod
    edited September 2022
    1 day ago high PLUS 1 day ago low is the sum of the high and low, not the range. So, if the high is 4 and the low is 3, the sum is 7. Range is the difference between high and low, which would be high minus low, or 4-3 so the range is 1.

    I'm guessing you want the today's close to be above yesterday's low, but only by some small fraction of yesterday's range. Or, to put it another way, today's close is in the lower portion of yesterday's range.

    That would look like this:

    and [close > 1 day ago low]
    and [close < 1 day ago low +[ [1 day ago high - 1 day ago low] / 3 ] ]

    There are two statements because you need to specify the top AND bottom of the area where you want the close to be (assuming I'm right about what you want).


    You could also multiply by a decimal fraction, and use the keyword "range" to simplify things:

    and [close > 1 day ago low]
    and [close < 1 day ago low + [ 1 day ago range * .33] ]

    So, if 4 and 3 are yesterday's high and low of a symbol in the database, the scan engine would plug in those numbers like this:

    close > 3 and close < 3+ (1 * .33), or

    close > 3 and close < 3.33

    And if today's close for that symbol is 3.25 , you would want that symbol on the results list because 3.25 fits both conditions (i.e., greater than 3 and less than 3.33)


    note:
    You will get a warning message because you are comparing values from different dates (meaning different offsets - today and 1 day ago) but it will run correctly.
  • Thanks very much. This does exactly what I had hoped for...[close < 1 day ago low +[ [1 day ago high - 1 day ago low] / 3 ] ]
  • Have to ask again, this stuff is mind boggling for me. If I want the close to be in the lower half of today's price range [Close < High-[[High-Low]]/2]] ? If I'd like for the close to be in the upper half of today's range [Close > Low+[[High+Low]]/2]]?
  • markdmarkd mod
    edited September 2022
    When you want price to be between TWO values, you have to specify BOTH values, the lower bound of the range and the upper bound of the range - that's two separate scan statements.

    One statement is: the price must be greater than some value - that value is the lower bound of the range.

    The other statement is: the price must less than some value - the upper bound of the range.

    So if you want the price to be in the lower half of today's range:

    and [close > low] // the lower bound, today's low

    and [close > low + [range * .5] ] // the upper bound, the midpoint, or half of today's range added to today's low

    If you want price to be in the upper half:

    and [close > high - [range * .5] ] // the lower bound, the midpoint, or half today's range subtracted from today's high.

    and [close < high] // the upper bound, today's high

    note: the order of the two statements doesn't matter. You can specify the upper bound first or the lower bound first. But, to keep things straight in your mind, it's a good idea to always choose one bound first - always lower or always upper. It's also a good idea to add a comment like // lower bound and // upper bound so you remember what you were doing when you come back to your scan later. All professional coders comment their code.

    p.s.

    if you want to calculate range yourself (there is nor reason to do that, it just makes things more complicated with brackets and signs, but if you do), range is ALWAYS the DIFFERENCE between high and low : [high-low].

    range is NEVER the SUM of high and low [high+low]. The sum of high and low will always be a number, but the number doesn't represent anything. In other words, it doesn't capture any useful relationship between prices.



  • [Close > Low+[[High-Low]]/2] for the lower half and [Close < High-[[High-Low]]/2] for the upper half? I like your way better because it's shorter and cleaner but are those two saying the same thing that you did? And thanks for the explanations.
  • When I put these into a scan and check it against chart pricing it seems to do the same thing. [Close > Low+[[High+Low]]/2]] for the upper half and [Close < Low+[[High+Low]]/2]] for the lower half.
  • What is it that it's asking in these equations when they add high + low and divide by 2?
  • markdmarkd mod
    edited September 2022
    The second set of brackets around high-low doesn't do anything. It just groups again what the first set of brackets has already grouped. So,

    [Close > Low+[[High-Low]]/2]

    probably should be

    [Close > Low+[ [High-Low]/2] ] // move the second bracket from after "low]" to after "/2";

    This says, add to the low half today's range.


    and then

    [Close < High-[[High-Low]]/2]

    probably should be

    [Close < High-[[High-Low]/2] ] // same thing


    You could probably get away without the second set of brackets altogether, and just say

    [close < high-[high-low]/2]

    where the /2 divides only the " [high-low] " and not "high-[high-low]" .

    But, I think its better form to use the brackets around it -

    high - [ [high-low]/2 ]

    That way, when you are debugging your scan, there's no doubt the /2 applies to only the [high-low]. But that's a style choice.

    ***

    [high + low] / 2 gives you the midpoint of the range - in other words, the simple average of high and the low.

    So, if you wanted the today's close in the bottom half of the range, you could say

    and [close > low] // today's low is the lower bound

    and [close < [high+low]/2] // today's midpoint is the upper bound.

    The reason to use

    low + [range * .5]

    is that its easier to change the upper bound

    low + [range * .3] // upper bound is lower 3 tenths of range

    low + [range * .25] // upper bound is lower quarter of range

    low + [range * .75] // upper bound is the lower three quarters of the range

    etc.

    Easier to change the decimal than figure out the right divisor for [high+low].
  • Thanks. I have thought about this one all night and I think that I finally understand how it works. Not sure that I understand the double set of brackets you mention, but I do understand that either way I go will produce the same results. The way you have done it is much easier to use and is cleaner. You may remember me asking about dividing by 3 just like you did above. Just replacing the /2 with /3 does not work. The results are no good.
  • I'm sorry to bother you with the same old thing yet again. I just can't figure it out yet. As another filter I'd like to ask for price to be above or below the midpoint between high and low and also between open and close of the previous day. I think that I have the long version put together, but I can't get the opposite or the short version to work at all. This is what I have for a long entry so far, it seems to work when I test it against a chart..... and [[Close > 1 Day ago Low] and [Close > 1 Day ago Low + [[1 Day ago High - 1 Day ago low] / 2]] and [Close > 1 Day ago Low + [[1 Day ago Open - 1 Day ago Close] / 2]]]. Can you help with the short version? Also, if you have time, I don't understand why we subtract high from low in the equation. Seems like we would want to add them instead?
  • markdmarkd mod
    edited October 2022
    As another filter I'd like to ask for price to be above or below the midpoint between high and low and also between open and close of the previous day.

    For the first part, choose one of these:

    today's close above today's midpoint

    and [close > low + [range * .5 ] ]

    today's close below today's midpoint

    and [close < low + [range * .5] ]



    To find today's close between yesterday's open and yesterday's close is more complicated.

    You need to account for two possible situations: was yesterday's close greater than (above) yesterday's open?
    or was yesterday's close less than (below) yesterday's open?

    and
    [ // yesterday closed above open
    [
    [ 1 day ago close > 1 day ago open]
    and [ close < 1 day ago close]
    and [close > 1 day ago open]
    ]

    or
    // yesterday closed below open
    [
    [ 1 day ago close < 1 day ago open]
    and [close > 1 day ago close]
    and [close < 1 day ago open]
    ]
    ]

  • When you want to find the difference between two values, you have to subtract.

    The distance between two points is a difference.

    Range is the distance between the high and the low, so you have to subtract.



  • Thanks again. That's very complicated
  • If you feel like it do these two expressions or equations look right for identifying tiny upper and lower candle shadows or wicks? Upper shadow and [[Open >= Low] and [Low > Open * .998]] Lower Shadowand [[Open <= High] and [Open > High * .998]]
  • In general, when looking for wicks or tails, you have to account for both the open and close.

    For a short wick (small shadow above the body) either the close or the open needs to be near the high.

    // wicks - shadow above the body

    and

    [
    [ // close near high
    [close < high - [range * .1]]
    and [close > high - [range * .2]]
    ]

    or
    [ // open near high
    [open < high - [range * .1]]
    and [open > high- [range * .2]]
    ]
    ]

    For a short tail (small shadow below the body) either the close or the open needs to be near the low.


    // tails - shadow below body
    and
    [ // close near low

    [ [close > low + [range * .1]]
    and [close < low + [range * .2]]
    ]

    or
    [ // open near low
    [open > low + [range * .1]]
    and [open < low + [range * .2]]
    ]

    ]

    You need all the parentheses exactly as shown or you will get an error from the syntax checker.
  • Good grief. Thanks
Sign In or Register to comment.