Find High and Low of Highest Volume Bar in a Range


hii, i want to calculate highest volume of 30 period and high and low of that highest volume day on rolling basis.
i m using function

here i am getting the wrong high and low of day of highest volume of rolling 30 period.Please help me in this



HHV function checks over PRECEDING periods. So your test is (probably) out by one day.

My test code seems to work…

highestvolume = HHV(V,30);
hvoldayhigh = ValueWhen(V == highestvolume, H, 1);
hvoldaylow = ValueWhen(V==highestvolume, L, 1);

I referenced Volume, not OI, but that should help you out.

Also, please check out the “How to use this site” at the top of the page, especially on how to post code. That way it will be easier for everyone when you get into larger code blocks, for others to help you out.

Hope this Helps.


Dear Sir,
thank you for ur help but it is not 100% correct.
let the first day from 30 period data have highest volume. and when next bar added and first data remove from calculation hhv(30), now some other bar now have highest volume. In this case

hvoldayhigh = ValueWhen(V == highestvolume, H, 1);
hvoldaylow = ValueWhen(V==highestvolume, L, 1);

this will not give high and low of day which now have the high volume in 30 bars.

Please check ur own and provide me solution

Thanks and Regards



When I PLOT from my code, it looks like the proper results to me. I get a High/Low price change on a the big volume days, and then it changes either with a higher volume day, or after what appears to be 30 days. I am just eyeballing it here.

Can you check by plotting the hvoldayhigh and low and see if it works for you. If not, show me the actual code you are using with “PROPER” code tags, so I can copy/paste in my system and then we can discuss exactly where we don’t agree.



@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,image


Thanks @portfoliobuilder and @snoopy.pa30 … now its working


@portfoliobuilder Nice work on the solution. My eyeball test was not sufficient. Now will have to analyze why valuewhen is not giving me the results I expected.

@veneet Sorry my eyeballing verification was not correct.