#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Scan for stocks that their price lies within two EMAs in the last two days

Got some 'brain-freeze' here and would appreciate some help (have received OUTSTANDING help in the past from "markd" - if available, would be great!)
OBJECTIVE: Would like to create two scans that both will look for stocks that their Daily price lies within 13- and 26-EMAs (let's call it the "Band"). Then each scan will include the following condition, either 1 or 2 (for the purpose of increasing the number of hits)
1) If the weekly slow EMA (here 26) is trending up(rising) then the prospective stocks' prices can ALSO be below the band
2) If the weekly slow EMA (again, 26) is trending down(falling) then the prospective stocks' prices can ALSO be above the band

For condition 1, here is some I wrote:
[type = stock] and
[country = us] and
[Close > 10] and
[Volume > 100000] and
//The Weekly slow EMA(=26) is rising- another way determining the slope is by using the Daily MACD(1,65,1) being above 0 -
// (see article at SCs << https://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:elder_impulse_system >>
[MACD LINE(1,65,1) > 0] and
// On the Daily chart, prices are in the Band (b/w EMA 13 & 26) or below it - so the max price among all highs in the last 2 days is less than EMA(13)
[[MAX(2, High) < EMA(26, Close)] OR [MAX(2, High) < EMA(13, Close)]] and
[FORCE(2) < 0]

For condition 2, here is what I wrote:
[type = stock] and
[country = us] and
[Close > 10] and
[Volume > 100000] and
[MACD LINE(1,65,1) < 0] and
[[MIN(2, Low) > EMA(26, Close)] OR [MIN(2, Low) > EMA(13, Close)]] and
[FORCE(2) > 0]

Assumptions made (which can be very wrong):
a) When a stock is trending up (determined by its Weekly slow EMA), its Daily slow EMA (26) will ALWAYS lie below its faster EMA (13)
b) When a stock is trending down (determined by its Weekly slow EMA), its Daily slow EMA (26) will ALWAYS lie above its faster EMA (13)
c) FORCE Index indicator will produce VALID stocks if scan is run intraday with 0(zero) look back (intraday = while market is open)

So what is the problem with the above coding? Well I have received results whereas under condition 1 the latest daily Low is well above the band.
So I know something (or everything) is fishy here.

George

• mod
edited January 30
I'm not sure why you are mixing time frames, but I'll assume that's what you really want. Your specification says weekly emas, but your scan is all daily, so that may explains the discrepancy.

So, it seems to me that this boils down to:

If the 26 is trending up, find closes below the 13 (assuming the 13 is above the 26)
If the 26 is trending down, find closes above the 13 (assuming the 13 is below the 26)

I would forget about MACD 1,63,1. You can determine if the weekly 26 is in an up or down trend by comparing the current value to a value somewhere in the past, let's say, 8 weeks ago.

So,
// weekly ema 26 trending up

// 26 ema rising
and [weekly ema(26, weekly close) > 8 weeks ago weekly ema(26, weekly close)]
// 13 above 26 (in other words, don't assume it has to be - say so)
and [weekly ema(13, weekly close) > weekly ema(26, weekly close)]
// close below 13
and [daily close < weekly ema(13, weekly close)]

Then, 26 trending down

// 26 ema falling
and [weekly ema(26, weekly close) < 8 weeks ago weekly ema(26, weekly close)]
// 13 above 26
and [weekly ema(13, weekly close) < weekly ema(26, weekly close)]
// close below 13
and [daily close > weekly ema(13, weekly close)]

When you mix time frames, keep in mind the scan engine considers the most recent update to be the last data point for every time frame. So, if you run a scan on Tuesday, the weekly time frame is calculated with Tuesday's data, not last Friday's. When you run it on Wednesday, your results could be different because the data has changed.

No idea whether the Force idea works.

If you actually want to do everything in the daily time frame, just change 8 weeks to 8 days, and edit out the modifier "weekly". You don't have to specify daily because that is the default (meaning, if there is no modifier in front of a value, the scan engine assumes you mean daily).