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.