Scan to combine price action and technical pattern


Category:
0
0

Hi Pete, thank you for the invaluable information on this site.  Truly priceless.

I’ve watched many of your videos and read a bunch of Q&As and I’ve tried to get a scan working that will return symbols whose EMA 10 has crossed the 20 and the 50 EMAs and are printing 3 candles with closes higher than the previous candle for 3 candles – I’ve come up with the following, but I’m getting a many positives and not consistently.

MovAvgExponential(“length” = 4).”AvgExp” crosses above MovAvgExponential(“length” = 8).”AvgExp” within 4 bars and MovAvgExponential(“length” = 4).”AvgExp” crosses above MovAvgExponential(“length” = 13).”AvgExp” within 4 bars and close is greater than close from 1 bars ago and close is greater than close from 2 bars ago and close is greater than close from 3 bars ago

Any idea how to improve this code to reduce false positives

thank you in advance,

BPSoCal

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 30, 2021 2:40 pm
214 views
0
Private answer

First you must define what is a "false positive". The code you provided is using moving averages that you did not include in your description. So I have no feedback to provide because if I were to take everything you have said literally I would say the your code is producing 100% false results. Meaning the code does not produce results which you have described as your goal.

I suspect there is much more to your specifications than you are able to describe at this time. For instance what is the timing for each of these events? Do you require a crossover on two pairs of moving averages first. And then check if  3 consecutive bars with higher closes? Or do all of these events happen at the same time? Should the first pair of moving averages cross before the second pair of moving averages?

I find that most folks that set out to build their scans don't understand how to clearly express what they see on the chart. Especially when it comes to the order of events. Once you can clearly express each and every component in a clear and logical fashion the problem usually solves itself.

Edit: After hashing out the missing details in the comment section below I have the following solution:

input consecutiveCloses = 3;
input maLengthOne = 10;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 20;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
input maLengthThree = 50;
input maTypeThree = AverageType.EXPONENTIAL;
input maPriceThree = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def maThree = MovingAverage(maTypeThree, maPriceThree, maLengthThree);
def firstCross = maOne[1] < maTwo[1] and maOne > maTwo;
def secondCross = maTwo[1] < maThree[1] and maTwo > maThree;
def higherClose = close > close[1];
rec trackFirstCross = if firstCross then 1 else if maOne > maTwo and trackFirstCross[1] > 0 then 1 else 0;
rec trackSecondCross = if trackFirstCross and secondCross then 1 else if maOne > maTwo and maTwo > maThree and trackSecondCross[1] > 0 then 1 else 0;
rec trackThreeConsecutive = if !trackSecondCross then 0 else if Lowest(higherClose, consecutiveCloses) > 0 and trackSecondCross then 1 else trackThreeConsecutive[1];
plot signal = trackThreeConsecutive and !trackThreeConsecutive[1];

I can't add a screenshot showing an example when editing an existing answer so I will add a new answer to the question and post the screenshot there. It should appear immediately below this solution.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on January 30, 2021 4:52 pm
0
Oh gosh, yes. I used the wrong EMAs in the code. My bad. My intent is to have the 10 EMA cross the 20 before it crosses the 50, and once it crosses the 50 print 3 consecutive candles with higher closes than the candles before.
( at January 30, 2021 5:04 pm)
0
Ok, thanks for confirming that error and providing more details. Before I attempt to solve this I have one more question. I now understand there is an order of operations. The question I have is in regards to the 3 consecutive higher closes. Do you require that this series of higher closes immediately follow the last crossover event or should the code allow for a maximum number of bars to pass before the three consecutive bars are allowed to validate the entire pattern? When you sit down to write things like this into code you become aware that there are a lot more details to consider then you first expected.
( at January 30, 2021 5:50 pm)
0
You're so right about that, lots more to consider than first meets the eye. Ideally, the series of higher closes will immediately follow the last crossover event. The first higher bar can start at the same time the 10x50 event and follow for 2 more bars. Thank you!
( at January 30, 2021 6:01 pm)
0
I have updated by answer to include the solution you requested.
( at January 31, 2021 10:08 am)
0
Private answer

Screenshot below shows an example of the signals this scan picks up on the chart. The solution is provided in the first answer I posted which is dated 1/30/21.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on January 31, 2021 10:08 am
0
Wow. This is impressive. Thank you for taking the time to figure this out. I suddenly don't feel bad for not being able to use the Condition Wizard to come up with this solution, I guess I hadn't figured how complex the request was. Thank you again! ~BP
( at January 31, 2021 12:27 pm)
0
Hi Pete, Can the code be modified to show the signal for bearish EMA crossovers and consecutive low candles?. I tried to flip the conditions in your solution but unable to get any signals. Thanks
( at January 31, 2021 12:34 pm)