Selecting periods of interest

Hi

I have a dataset from which I have identified some periods of interest and created two new waves, which for each row one takes the datetime value the period starts and the other wave take the datetime value when the period ends.

What I want to do is to select those two start and end values for row 0 and scan through another wave (FJD) that contains other datetime values and see if it finds values inside the range of those start and end values and mark them (maybe with another wave that serves as an index). Then do the same for row 1 and so on until it has done it for all ranges. The waves that have the start and end of the periods do not have the same number of points a the wave FJD, which is the one I want to scan through. I have attached a file with the waves and the last function I tried.

Any ideas on how I can accomplish this?
For selecting periods_test.pxp