Consecutive open and close below upper keltner channel


Category:
0
0

Hey Pete, I’m looking for a scan that allows me to filter stocks that have the past 15 consecutive daily candle open and closes below the value of the current upper keltner channel band.

Marked as spam
Posted by (Questions: 12, Answers: 20)
Asked on April 2, 2020 6:17 pm
103 views
0
Standard settings for the keltner channel (factor 1.5 & length 20)
( at April 2, 2020 6:24 pm)
0
Private answer

Here you go. Just copied the code from the built-in version. Added one user input and a two additional lines to capture the signal:

input consecutiveBars = 15;
input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def upperBand = average[-displace] + shift[-displace];
def undesirableCondition = open > upperBand or close > upperBand;
plot scan = Highest(undesirableCondition, consecutiveBars) < 1;

Edit: It took me a while to realize the original request was not for the open and close of the last 15 bars to be below the current value of the upper Keltner channel. What is really being requested is for the open and close of the last 15 bars to be below the value of the upper Keltner channel on the LAST bar on the chart. For each candle on the chart, the current value of the Keltner channel is the value exactly in line with each candle. (as opposed to being shifted to the left or to the right). So here is another version of the scan that compares the open and close of the past 15 candles to the value of the upper Keltner channel at the LAST bar on the chart.

input consecutiveBars = 15;
input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;
def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def upperBand = average[-displace] + shift[-displace];
def lastBar = IsNaN(close[-1]) and !IsNaN(close);
def valueAtLastBar = if lastBar then upperBand else 0;
def targetValue = HighestAll(valueAtLastBar);
def undesirableCondition = open > targetValue or close > targetValue;
plot scan = Highest(undesirableCondition, consecutiveBars) < 1;

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on April 3, 2020 7:12 am
0
Thank you Pete. Only problem is it gives me stocks like XSPA that have opened 8 bars ago over today’s current upper keltner value D: also when I increase it to 17 it gives me a few more doing the same
( at April 3, 2020 9:09 am)
0
What time frame are you applying to the study filter of the scan?
( at April 3, 2020 11:07 am)
0
The daily time frame
( at April 3, 2020 1:38 pm)
0
When I run the scan on a daily time the ticker symbol XSPA does show up in the scan results. When I plot XSPA it does not have any opens or closes above the upper Keltner band within 15 bars. When spot checking several of the items in the result list the only errors I found were for stocks that lacked trade data for one or more days within that 15 day span. So far as I can see the scan is working perfectly.
( at April 3, 2020 4:07 pm)
0
On 03/25/2020 XSPA opened at $0.40. Today’s current upper Keltner channel value was $0.339 (on the mobile app). Because XSPA opened at $0.40 eight bars ago it shouldn’t have showed up on the scan since its within 15 consecutive bars. More results will appear if you increase the consecutive bars to say 17 or 18 where they’ve opened or closed greater than today’s upper keltner channel value as well. I know the code is doing it’s job but not for this particular question because I most likely confused you into writing the code as such. Sorry.
( at April 3, 2020 4:48 pm)
0
XSPA must be a typo. Because the price of that instrument hasn't been higher than 32 cents in the past month: https://www.marketwatch.com/investing/stock/xspa Perhaps you are looking at an intraday chart that includes extended hours session? Otherwise, we seem to be in completely different universes.
( at April 3, 2020 7:02 pm)
0
Oh that’s because you’re using a line graph. If you enable the advanced charting and click candlestick display it’ll show you that it was higher. Line graphs aren’t as accurate. https://stockcharts.com/h-sc/ui?s=XSPA I just turned off the extended hours on my mobile app still shows me .40 being the open
( at April 3, 2020 7:22 pm)
0
I have updated my answer to provide the scan I believe you are requesting.
( at April 3, 2020 8:39 pm)