How to "hover and wait"

I want to write some code that recognises 3 events which can occur in any sequence over a number of days. These are:
1 three EMA's in order, say 5>15>30 for an uptrend, and vice versa for down;
2 Cross where PDI>MDI, and;
3 ADX ramps up prior to or after point 2 above.

Most of this comes from Charles Kirkpatrick's book Investment & Trading Strategies

I don't need the code written for me, otherwise I won't learn, I just need to get the logic right. I'm assuming the code would provide recognition of 1 of the 3 conditions then 'hover' waiting for the other two to occur. It's the hovering process that has me stumped.

So could someone please point me in the right direction?

Many thanks,



I am assuming by hovering you mean waiting until all 3 conditions are satisfied because they dont occur on the same bar.

For that you can use FLIP, to maintain state of each separate signal.
AFL Function Reference - FLIP (

Once each condition is met, you just check when the count is 3 meaning all are on and then take the required action.

Thank you. Am I correct in assuming that these FLIPs are embedded in an IF type process and will trigger action once the count is 3?

Did you search the forum for 'Flip' examples?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.