@snoopy.pa30 @veneet due to our lack of familiarity with both how AmiBroker functions work and all of the available functions, this took me a long time to solve. I am certain a more experienced (or just smarter) user could have done this in a couple of minutes instead of a couple of hours.
@snoopy.pa30 Run an EXPLORE instead of a Plot to see what values your code is generating. It is not doing what you think it is doing ( see below for a screen capture of your code after my attempt at a solution).
My attempt is here using 20 bars to make it easier to debug during my Exploration (so @veneet you can change the 20 to a 30) , and you can delete the Exploration if you want as it is there to debug the code.
BarsSinceHighestVolume = HHVBars( V, 20 );
high1 = Ref( High, -BarsSinceHighestVolume );
low1 = Ref( Low, -BarsSinceHighestVolume );
// Explore //
Filter = 1;
dynamic_color = IIf( HHV( V, 20 ) != Ref( HHV( V, 20 ), -1 ), colorLime, colorDefault );
AddColumn( High, "High" );
AddColumn( Low, "Low" );
AddColumn( Volume, "Volume" );
AddColumn( HHV( Volume, 20 ), "HHV20", 1.0, colorDefault, dynamic_color );
AddColumn( BarsSinceHighestVolume, "BarsSinceHighestVolume", 1.0, colorDefault, dynamic_color );
AddColumn( high1, "high1" );
AddColumn( low1, "low1" );
With this output that I have marked up beyond recognition, so run your own.
Now for @snoopy.pa30 output,