I have two occurrences, Cond1 and Cond2. In between these two bars there is a variable number of bars, but I want to identify when: 1.) all the bars share at least a tick of the Cond1 bar and 2.) The range of every bar between Cond1 and Cond2 is lower than the range of the Cond1 bar.
What would be the most efficient code to define this?
I don't quite understand your two rules.
1.) all the bars share at least a tick of the Cond1 bar
Are you trying to say that each bar includes a price that is between the High and Low of the Cond1 bar?
2.) The range of every bar between Cond1 and Cond2 is lower than the range of the Cond1 bar.
What does it mean for one range to be "lower than" another range? That the high is of each bar after Cond1 is lower than the Cond1 High?
Yes. Each bar includes a price between the High and Low of the Cond1 bar.
No I should have said a smaller range or narrower range. H-L of all bars is less than H-L of Cond1 bar. This is what I am defining as a consolidating area.
Sorry for not being clear.
This should get you started. Obviously my cond1 is just for testing since you didn't reveal your Condition 1 rules. Everything after the Filter command is also for verification only.
range = H - L;
cond1 = DateNum() == 1180323;
cond1High = ValueWhen(cond1, H);
cond1Low = ValueWhen(cond1, L);
cond1Range= ValueWhen(cond1, range);
isOverlap = LLV(L < cond1High AND H > cond1Low, BarsSince(cond1));
isConsolidation = LLV(range < cond1Range, BarsSince(cond1));
cond2 = isOverlap AND
Filter = True;
Thank you mradtke, this is very helpful.
In that case you should "like" the post or mark it as the solution.