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.
Scanning for a failed downside breakout
I am looking for a scan that searches for the following setup:
- Price has been in a downtrend
- Price takes out the prior low but not by much and then closes above the prior low
- MACD shows a shallower bottom on the pierce of the low than it did at the low that has been pierced (a divergence)
Can anyone help me set this up?
If this is too hard, is it possible to do it without the divergence between price and MACD? So only the takeout of the low by a small amount and then closing above the low that has been taken out?
Also, what do you mean by a downtrend? In what time frame - in other words, are both the 200MA and 50MA declining, or just the 50MA above a rising 200MA, or something else?
Often the problem in writing a scan is not the grammar or the syntax or even the logic, but deciding exactly what it is you want. So the more specific you can be the better. Your description is good - it just needs to be a little more concrete, in the way the above questions suggest.
So with that being said:
For this example I would define a downtrend as the 13EMA has to be below 26EMA for the previous 50 days. This is not the problem though, I have this programmed already.
What I mean by the prior low is the low from the last decline. So not yesterday's low. This has proven to be a bit of a problem to program.
For MACD I want it to have a decline to a deep low, then a rise above 0 and another decline to a higher low. I can add a picture of this in my next reply if necessary.
// test for lower channel has been at the same level for some number of bars
and [1 day Lower Price Chan(21) = 7 days ago Lower Price Chan(21)]
// test for break below and close above that price channel
and [1 day ago Lower Price Chan(21) x low]
and [1 day ago Lower Price Chan(21) < close]
// for PPO (per cent version of MACD) generally rising
and [PPO Line(12,26,9) > 20 days ago PPO Line(12,26,9)]
and [PPO Line(10,26,9) < 0]
and [10 days ago min(20, PPO Line(12,26,9)) < 25] // or some number
and [max(15, PPO Line(10,26,9)) > 0]
Tweaking the parameters will get you different kinds of situations. No one scan is going to get them all. Also, not every hit will be exactly what you want. But it sounds like you probably know that already.
What I have been trying is to have the prior low defined as something like this:
6 days ago min(50,low) //the low of the last 50 days from the point of view of 6 days ago (so day 7 to 56 looking back).
Then I would define the break as:
min(5,low) < 6 days ago min(50,low) //the low of the last 5 days is lower than the low of the 50 days prior to those 5 days.
But this does seem to work. What am I doing wrong here?
so for the first part, I think you want to say (I'm omitting syntax)
6 days ago low = min(50, low)
in other words, the low 6 days ago is the lowest low for the 50 days prior to that 6 days ago low
then I think you want to say
6 days ago low x low -
in other words, today's low is the first low to break the six days ago low
and then, close > 6 days ago low
Or, do you want no gap between the lows? Do you have a chart example?
If you don't want the exact break of the channel, write the scan so the break happens 1 or 2 or however many days ago (you could adjust the code above), and then check for the low below yesterday's low and close above yesterday's low.
You could also check that the channel is lower than some period longer than the channel - say 100 days - that gets you the down trend in that time frame. Or just test for a declining MA - say MA63 < 20 days ago MA63.
Does that work?
To put them on your chart, go to the chart workbench, click the Overlay drop down. Price Channels is located a few up from the bottom. The default is 20 bars, but you could change that to 50 or 60 for your purposes.
Then to scan for Price Channels, on the scan workbench, find the Technical Indicators drop down. A little more than half way down you will find Upper Price Chan, Middle Price Chan and Lower Price Chan. They are grouped together with Upper MA Env and Upper Kelt Chan.