#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Hi, I am trying to scan today's price spread is narrower than yesterday's price spread.

Price spread is defined as absolute value of the high and low's difference.

and [absval(high-low) < absval(yesterday's high - yesterday's low)]

The above scan returned nothing, so something must be wrong. Could anyone help? Thanks!

• mod
edited October 2016
If I remember correctly, the absval() function cannot evaluate an arithmetic expression, although that's not clearly documented. I think it's intended to compare indicators that resolve to a single value, where that value could be either positive or negative - like MACD Line, for instance. @gord might know, if he sees this question.

In any case, for your scan, you don't need an absolute value because the high will always be greater than the low (in some cases they could be equal, but the high can never be less than the low).

The difference between the high and low can be expressed using either "range" or "ATR(1)". Range looks at just the high and low made during the session. ATR (average true range) looks at the the high, the low AND the prior close. If that close is higher than the session high, it substitutes the prior close as the high. Vice versa for the low - if the prior close is lower than the session low, it substitutes the prior close for the low. The "1" parameter means the divisor for the average is 1, and it looks at only one data pair to average, so it is effectively the difference of one day's high and low.

So, here are two possible scans:

//and [range < 1 day ago range]

//and [ATR(1) < 1 day ago ATR(1)]

You could copy either one, or both, to your scan and remove the "//" from in front of the one you want to use.

I mistyped in my original post, I meant spread is defined as the difference between open and close. Since I don't know the relationship between open and close, that's why I tried to use absval.

and [absval(open - close) < 1 day ago absval(open - close)] didn't return anything, I suspect it's as you said absval doesn't work this way.

Help is still needed. Thanks!

• mod
Here's the reply I got some time ago from support re using absval( )

"The issue is with the absolute value function. Currently, it is unable to accept date offsets, like “I day ago,” even when it appears in the rank by command."

If absval( ) could handle it, I think your scan would be:

and [absval(open - close) < absval(1 day ago open - 1 day ago close)]

• mod
edited October 2016
I think what you have to do is write an extended "or" condition that considers the possible state combinations of the two sets of opens and closes, and then multiply the negative elements by -1 to get positive numbers, then compare the positive numbers. It's kind of a brute force solution. Maybe someone else can do it more elegantly (like @ekwong )

So the states for "close - open" (or "open - close", whichever you find easier to work with) would be:

day 1 positive [close - open > 0] (an up close, most of the time)
day 2 positive

day 1 negative [close - open < 0] (a down close, most of the time)
day 2 positive

day 1 positive
day 2 negative

day 1 negative
day 2 negative

To compare them, make both positive. So, for instance, for the second state pair, for day 1 negative you would multiply day 1 negative by -1, then compare it to day 2 positive.

The phrase below makes day 1 negative result positive:

[[close - open]* [-1]]

So the second "or" condition would be

// yesterday's close below the open
and [[1 day ago close - 1 day ago open] < 0]
// today's close above the open
and [[close - open] > 0]
// make yesterday's difference positive, compare to today's difference
and [[[1 day ago close - 1 day ago open]*[-1]] > [close - open] ]

The three statements are one condition. The first two lines account for the second combination of states for day 1 and day 2 listed above. The third statement compares day to day 2 after making day 1 positive.

So your complete "or" statement skeleton would be

and
[

[ condition 1 (compares day 1 positive and day 2 positive) ]

or

[ condition 2 (compares day 1 negative and day 2 positive - the 3 lines above) ]

or

[ condition 3 (day 1 positive, day 2 negative) ]

or

[ condition 4 (day 1 negative, day 2 negative) ]

]

I didn't run any of this through "check syntax" so you will have to be careful about keeping track of brackets.
• mod
edited October 2016
Sorry, day 1 negative should be

[ [1 day ago close - 1 day ago open]* [-1] < 0]