Snap.PNG

This is easiest to explain with a screenshot.
I am looking for a macro that will input "1"s in the next 20 cells in coloumn I when a number is coloumn D exceeds the numbers in coloumn E. This action should, however, be stopped if the if a number appears in coloumn D that is smaller than the numbers in coloumn G. The opposite should be the case in coloumn J where "1"s are inserted if the numbers in D drops below the numbers in G, and stopped within 20 periods if a number exceeds the numbers in coloumn E.

In this way there can be less than 20 consecutive "1"s, but also more if the border is "breached" once again during the period.

I have tried this using "IF" functions in Excel, but couldn't get around it. There must not be one observation that inputs "1" in both coloumn I and J.

Thanks!