Trying to create a scan to capture moving averages converging in a tight bunch, in this example on COUP I'm trying to capture the SMA(10), SMA(21), SMA(50), EMA(23) and EMA 65 in a tight bunch. I'm really trying to capture price of a stock on an average closing basis within 1-3% of it's 21day, 50day, 65Day closing price.
For example (screen capture) trying to capture the moving average convergence as seen around the 8 of Jan 2019
Only my 2nd time to try and create a scan. I've tried this in a few different ways , for example:
//MARKET INDICIES
[
[group is DOW30]
OR [group is SP500]
OR [group is NASDAQ100]
]
and [SMA(10 ,close) >= SMA(50,close) * 0.99]
and [SMA(10 ,close) <= SMA(50,close) * 3.01]
and [SMA(21,close) >= SMA(50,close) * 0.99]
and [SMA(21,close) <= SMA(50,close) * 3.01]
and [EMA(23,close) >= SMA(50,close) * 0.99]
and [EMA(23,close) <= SMA(50,close) * 3.01]
and [EMA(65,close) >= SMA(50,close) * 0.99]
and [EMA(65,close) <= SMA(50,close) * 3.01]
//and [volume > yesterday's volume * 1.3] // Volume up 30% from yesterday
and [PctRelative (63,$spx) > 0 ] //quarter history of outperformance
Answers
Thank you for any help provided.
//MARKET INDICIES
[
[group is DOW30]
OR [group is SP500]
OR [group is NASDAQ100]
]
and [PctDiff(close,SMA(10,close)) >= -1] //Price greater than 1% from SMA10
and [PctDiff(close,SMA(10,close)) <= 3] //Price less than 4% from SMA10
and [PctDiff(close,SMA(21,close)) >= -1] //Price greater than 1% from SMA21
and [PctDiff(close,SMA(21,close)) <= 3]
and [PctDiff(close,SMA(50,close)) >= -1]
and [PctDiff(close,SMA(50,close)) <= 3]
and [PctDiff(close,EMA(23,close)) >= -1]
and [PctDiff(close,EMA(23,close)) <= 3]
and [PctDiff(close,EMA(65,close)) >= -1]
and [PctDiff(close,EMA(65,close)) <= 3]
and [PctRelative (63,$spx) > 0 ] //quarter history of outperformance
That might solve your problem. If not, here are other suggestions:
Back test across many different dates, if you haven't done so already. These conditions are most likely to be true when the symbol has been ranging for period of time. Most stocks move together, so you are likely to get more hits when the market itself is ranging.
Try the max( ) and min( ) functions to test whether the MAs have been close within some period of time, maybe a week or two - that way you conditions do not have to be ALL true on one particular date. Also, it my not be necessary to test for the very shortest MAs, since those will always be close to price.
Also, you could use the longest term MA as the "anchor" - the shorter MAs within x per cent of the longest (slowest) MA. You almost do this in the first example, except for the last couple of lines. Probably you should also test that the longest term MA is rising (greater today than x bars ago).
Also, for testing, I would drop the performance requirement vs. the $SPX.
[type = stock]
AND [GROUP IS NOT ETF] //Excludes ETFs from scan
AND[[exchange is NYSE] or [exchange is NASD]
AND [Daily SMA(20,Daily Volume) > 100000]
AND [SMA(10,close) > SMA(200,close) * 0.99]
AND [SMA(10,close) < SMA(200,close) * 1.02]
AND [SMA(21,close) > SMA(200,close) * 0.99]
AND [SMA(21,close) < SMA(200,close) * 1.02]
AND [EMA(23,close) > SMA(200,close) * 0.99]
AND [EMA(23,close) < SMA(200,close) * 1.02]
AND [EMA(65,close) > SMA(200,close) * 0.99]
AND [EMA(65,close) < SMA(200,close) * 1.02]
AND [1 DAY AGO SMA (200) > 63 day ago SMA (200) ]
]
[type = stock]
AND [GROUP IS NOT ETF] //Excludes ETFs from scan
AND[[exchange is NYSE] or [exchange is NASD]
AND [Daily SMA(20,Daily Volume) > 100000]
]
and [max(10,close) < SMA(21,close)*1.03]
and [min(10,close) > SMA(21,close)*0.99]
and [max(10,close) < EMA(23,close)*1.03]
and [min(10,close) > EMA(23,close)*0.99]
and [max(10,close) < EMA(65,close)*1.03]
and [min(10,close) > EMA(65,close)*0.99]
AND [1 DAY AGO SMA (200) > 63 day ago SMA (200) ]
I seem to be getting some results close to what I'm looking for, but then I get something like this (circled in red) where the moving averages are quite a distance from each other.
You could also try max and min of the shorter MAs vs the long MA.
[exchange is NYSE] or [exchange is NASD]]
and [
[group is SP500]
or [group is sp400]
or [group is sp600]
]
and [sma(200,close) > 63 days ago sma(200,close)]
and [sma(10,close) > sma(200,close)*.98]
and [sma(21,close) > sma(200,close)*.98]
and [sma(63,close) > sma(200,close)*.98]
and [sma(10,close) < sma(200,close)*1.02]
and [sma(21,close) < sma(200,close)*1.02]
and [sma(63,close) < sma(200,close)*1.02]
All the results fit the criteria, BUT, they all look very different. You would think that convergence of MAs on a long term rising stock would be a winning approach, but, maybe it depends on how it happens, e.g., maybe the intermediate term MA(s) should not have crossed the long term MA recently, etc. The problem is there are so many variations for MA paths. It may be that a scan can only narrow the field from which you can choose, by other means, plausible candidates.
https://academy.edgerater.com/guppy-multiple-moving-average-indicator-and-template/