# 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
high1=valuewhen(hhv(oi,30)==oi,h,1);
low1=valuewhen(hhv(oi,30)==oi,L,1);

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

Veneet,

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.
Snoopy

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

Veneet,

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

@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( high1, "high1" );
AddColumn( low1, "low1" );
``````

With this output that I have marked up beyond recognition, so run your own.

Now for @snoopy.pa30 output,

5 Likes

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.

Snoopy

Iâ€™m trying to work out how to calculate HHV of Volume Bar Of "Previous day" in an intraday timeframe, e.g. 5mins chart. I would appreciate If anyone has code to share or could guide me on how to do this. Regards, Nick.

Something like this untested snippet should work:

``````prevDayHighestVol = TimeFrameExpand(Ref(TimeFrameCompress(V,inDaily,compressHigh), -1), inDaily, expandFirst);
``````

You should still take a look at the documentation for those functions so you understand how this works.

1 Like

Sir,
I am using following code to scan current highest volume bar in 5 min time frame...and its working like a charm for me.
All I need is that the color of that particular 'VOLUME BAR' should turn into 'orange' or any other color...I will be glad if anyone could help me.....My code is as under`

```````dailyMaxVolume = TimeFrameCompress(V, inDaily, compressHigh);
prevDayMaxVolume = TimeFrameExpand(Ref(dailyMaxVolume ,-1), inDaily, expandFirst);
high1 = Ref(V,0)> prevDayMaxVolume;`
``````

@Nick1985
use IIf function....
IIf high1 true colorOrange else colorDefault

Sir,
If you can help with entire volume plot formulae ill be very grateful