Off the top of my head:
wave = iif( c >= ref( c, -1 ), h, l ); //change >= if want another condition for the case where c == ref( c, -1 ) - could use, for example, wave = iif( c > ref( c, -1 ), h, iif( c < ref( c, -1 ), l, c ) );
plot( wave, "", colorwhite, styleline | stylethick );