I’m trying to automate a strategy where it has to evaluate 2 conditions that are mutually exclusive, i.e. the second one is met only after the first one is no longer met (the 2nd is dependent on the 1st), and when this happens and the 2nd condition takes place after the 1st condition, then the strategy generates an Entry signal. So these 2 conditions take place in a successive order BUT these 2 conditions do not necessarily take place consecutively in time, i.e. sometimes once the 1st condition takes place then the 2nd condition takes place in the next bar, some others times the 2nd condition takes place 2 bars after, but the problem I found is where the 2nd condition take place after many bars from the 1st condition, for example, now I visually check a couple of cases where there are 50-70+ bars of separation between the 1st and 2nd condition, and in these cases I see the strategy works as should if you would trade it in a manual way, but now I’m looking for automate those cases where are a considerable separation between the 2 conditions.
...
protected override void OnBarUpdate()
{
...
if ((lineH[0] < lineJ[0] && lineH[0] < lineK[0]) && (lineH[1] > lineJ[1] && lineH[1] > lineK[1]) || (lineH[2] > lineJ[2] && lineH[2] > lineK[2]))
{
//generate an Entry signal
}
...
}
...
I’ve seen some strategy examples to see if I find a similar case but the strategies I’ve seen normally evaluates their condition for 2-5 bars and done, but the problem in my case is the number of bars between the 2 conditions is not a fixed number and how to handle those cases where it takes some time to meet the 2nd condition.
I need help about to know how we can handle this kind cases.
Thank you in advance!

Comment