Help with Last Occurring Signal Script

Hi. I am trying to capture the last time a Signal occurred.
I am capturing a high pivot as a Signal and tried using BARDATE where the Signal occurs and then returning the last BARDATE.
Nothing appears to happen when I use this in a Show Bar:

cond1 = HIGH() > HIGH(OFFSET=1); 
cond2 = HIGH() > HIGH(OFFSET=-1); 
sig = cond1 and cond2;  
v2 = BARDATE(); 
v3 = VALUEWHEN(sig, v2); 
v4 = v2 == LAST(v3); 
v4

Hi,

I think the issue is with the V3 variable, the two items within the brackets need to swap order.

cond1 = HIGH() > HIGH(OFFSET=1); 
cond2 = HIGH() > HIGH(OFFSET=-1); 
sig = cond1 and cond2; 
v2 = BARDATE(); 
v3 = VALUEWHEN(v2, sig); 
v4 = v2 == LAST(v3); 
v4

Thanks for the correction. However, I could not get it to work:

cond1 = HIGH() > HIGH(OFFSET=1);
cond2 = HIGH() > HIGH(OFFSET=-1);
sig = cond1 and cond2;
v2 = BARDATE();
v3 = VALUEWHEN(v2, sig);
v4 = v2 == LAST(v3);
v4

But when I tried the following instead, it worked:

cond1 = HIGH() > HIGH(OFFSET=1);
cond2 = HIGH() > HIGH(OFFSET=-1);
sig = cond1 and cond2;
v2 = BARDATE();
v3 = VALUEWHEN(HIGH(), sig);
v4 = HIGH() == LAST(v3);
v4

The problem with the latter script is that the same High, even if rare, can possibly occur multiple times and I want the last bar where the Signal is true.

Which part of the adjusted script did not work for you?

I’ve used it here and checked it against the raw output of the SIG variable it is producing the expected result.

ex18

It appears to be working now.
For some reason it was slow to appear and I had to click somewhere on the chart after applying the Show Bar.
Might need a reboot.
Thanks for clarifying.