Duplicate: Bars since price was this high/low

You can't do that with ValueWhen because it scans in single direction, while what you are asking needs scanning in two opposite directions.

BTW: this is a duplicate topic. Existing topic already provides solutions Bars since higher or equal value - #16 by Tomasz