#### Howdy, Stranger!

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

# scan for all stocks with a close within 10% of SMA(20)

To avoid more volatile stocks, I'm trying to filter out any stocks over the last 90 days that had a close great than 10% of SMA(20)

I came up with the following: [max(90,close) < SMA(20,close)*1.1]

I'm still getting results where closings are well above 10% of the SMA, and thoughts how to fix this?

• mod
edited December 2019
Your question is similar to this one:

https://scan.stockcharts.com/discussion/comment/3867#Comment_3867

PPO uses an EMA instead of an SMA, so it's not exactly the same, but hopefully close enough for a filter.

The scan for the most recent close would be a range of less than 10 per cent above 0 and less than 10 per cent below 0 (0 represents the EMA in the PPO indicators). So:

and [PPO(1,20,1) < 10]
and [PPO(1,20,1) > -10] // negative numbers closer to zero are greater, so ">", not "<"

But, since you are looking for behavior over a period of time, you have to test for max and min values (as your shot at it above suggests).

and [max(90, PPO(1,20,1)) < 10]
and [min(90, PPO(1,20,1)) > -10]

I haven't run this scan, so test the results before you use it. To verify results, you need a chart style with PPO(1,20,1).

• it seems like a good solution but when testing it i kept getting syntax errors and couldnt debug it.

as an alternate, i tried:
and [1 week ago pctchange < 5]
and [2 weeks ago pctchange < 5]
and [3 weeks ago pctchange < 5]
and [4 weeks ago pctchange < 5]

which seems to function okay...
however, i couldnt find a what the pctchange referenced...>is it price?
how could i apply pctchange to closing or to difference between high and low over a single week period?
• after playing with PPO, i think it's the best solution, just cant seem to get rid of the

-- Could not parse "PPO" located in the clause "MAX(90, PPO(1,20,1))" -- error
• ✭✭
edited December 2019
When you SELECT the option from the Technical Indicators Dropdown list and add it to your scan workbench it looks like this:

and [PctChange(10,close) > 10]

You tell the scan engine what you want to see. An option for your "week ago" requirement could be to change the 1st and 2nd 10 to 5. 2 weeks ago you can leave the 1st 10 as 10 and change the 2nd to 5. 3 weeks ago you can change the 1st 10 to 15 and the 2nd to 5, etc....

and [PctChange(5,close) > 5]
and [PctChange(10,close) > 5]
and [PctChange(15,close) > 5]

It's better to select the options using the dropdowns and then editing them to meet your requirements. The syntax is set correctly to start with.

If you were to look at the PPO from the Dropdown menu, the PPO is available in 3 expressions. The PPO Line and the PPO Signal and the PPO Hist.

and [max(90, PPO Line(1,20,1)) < 10]
and [min(90, PPO Line(1,20,1)) > -10]
• thanks, let my try these out
• mod
edited December 2019
@JACKSON That was my mistake - sorry! You should test for PPO Line, as @lmwkin suggests.
• thanks... just to confirm, the PPO Line is the best option?... it seems to be....when i tried it just now it seemed to filter out the more volatile stocks...

-- a question on time frames, in the phrase ' [min(90, PPO Line(1,20,1)) > -10] ', 90 refers to 90 days, is it possible to substitute ' 3 months ' in lieu of ' 90 ' in the phrase?
• mod
edited December 2019
Yes, PPO Line is the best option.

No, you cannot substitute 3 months for 90.

min( ) is a function, and all functions expect specific types of data in a specific order. So, for min( ), the first function must be a number. That number tells the function how many bars of data to look at.

You can use most functions in any time frame (if your subscription allows) - daily, weekly or monthly. But, you will get slightly (or more than slightly) different results because each time frame "samples" the data differently.

So, daily looks like you have seen it:

min(90, PPO Line(1,20,1)) > -10 // this looks at 90 daily bars of data - in this case, 90 daily PPO values

Weekly would look like this - notice the modifiers - you need both to get accurate results:

weekly min(12, weekly PPO Line(1,20,1)) > -10 // this looks at 12 weekly PPO values.

And monthly would look like this:

monthly min(3, monthly PPO Line(1,20,1)) > -10 // this looks at 3 monthly PPO values

So, all three conditions look at approximately 3 calendar months of data, but the first calculation looks at 90 bars, the second looks at 12, and the third looks at only 3. The method for each calculation will be the same, but the data for each is different, so the results will be different.

Functions for the scan engine are documented here:

https://support.stockcharts.com/doku.php?id=scans:functions

Extra detail on min/max functions is here: