Find the first 3 highest volume bars in a specific period

Forums ProRealTime English forum ProBuilder support Find the first 3 highest volume bars in a specific period

Tagged: ,

Viewing 15 posts - 1 through 15 (of 15 total)
  • #148350

    Dear All

    I tried to find the answer in old topics but unsuccessfully.

    I’d like to know how to find and store the first 3 (or more, 4, 5 does not matter) bars with highest volume in the last 50 bars.

    I mean taking into consideration a period back to 50 bars I want to store in 3 different variables the value of the index bar related to the first 3 high volume bars.

    thank you

     

    #148380

    There you go (not tested):

    af the end of the iterations COUNT will retain the number of  variables with a high volume, it can be any number from 0 to 3. Bar1 will retain the first bar index, if any, Bar2 the second one and Bar3 the third one.

    This works with v10.3+, it’s a bit awkward to add other variables, if needed.

    This one, instead, will work with v11 only but it’s easier to increase the number of variables needed:

    $MyBar[..], from 0 to 2, will retain values if COUNT > 0.

    #148384

    Ciao Roberto

    thank you for your answer.

    I was not able to develop the code because I didn’t know the powerful  sintax

    HiVol = (Volume = highest[50](Volume))

    Instead of   HiVol =  highest[50](Volume), is yours able to define the highest volume bar in such a dynamic way? Can you explain me it better?

    Also I understood, I did not wrote very clear, my aim is actually to find the highest 3 bars in a period of 50 bars. Does your code do that, or simply it finds the first 3 bars going back to the past (and after it stops)? It seems so.

    After getting these 3 bars, I also need to put them in ascending or descending order.

    I know we can do that in the way below, but if I need more than 3 bars it becomes complicated:

    Sorry for the programming language but it is just to explain.

    Grazie per l’aiuto

    Roberto

     

    #148398

    HiVol = (Volume = highest[50](Volume))
    Instead of   HiVol =  highest[50](Volume), is yours able to define the highest volume bar in such a dynamic way? Can you explain me it better?

    The first determines a logical value (true or false), while the second assigns a volume value to the variable,  which is not what you need because any bar would have a highest value.

    The code scans the last 50 bars, which you can replace with any number or BarIndex to scan all previous bars.

    If you need to increase 3 to a higher number, then it’s easier using the second code snippet, but only if you are using v11,

     

    #148410

    Hello

    1)  If Volume[i] = HiVol[i] Then

    Compares the i -volume bar with a  logical value (?) I am not sure it is going to work.

    2) since the formula is

    HiVol = (Volume = highest[50](Volume))

    when you do   If HiVol[i] Then
    you scan always and only the highest of 50 bars.
    So let’s imagine i=10 the scan is from bar 10 to bar 59 which is not good, I need to scan only the last 50 bars.
    HiVol(10) tells me if 10 bars ago the actual bar at that time was the highest of the last 50 bars so, based on the present time, if it was the highesr from bar 10 to 59 (50 bars).
    I think it is not so easy to get on a period of ie 50 bars the highest 3, 4 or whatever bars and their bar index.
    What do you think?
    #148411

    You are right, that line ahould read:

     

     

    #148412

    Counter i always starts from 0 up to 49. In that range there should be at least one highest volume, sometimes 2 or 3.

    #148416

    Sorry if I chat again but I think it is important.

    HiVol = (Volume = highest[50](Volume))

    Example i=10

    HiVol[10] =  (Volume[10] = highest[50](Volume))

    How does 50 work?

    In my opinion the research of the highest volume bar goes from bar 10 back to 59.

    And the formula is true if the bar 10 is the highest of the last 50 bars back, otherwise it is false.

    #148422

    Yes, it scans the last 50 bars for the highest volume in 50 bars.

    In bar 0 it will find the highest from bar 0 to bar 49, in bar 1 it will find the highest from bar 1 to bar 50 and so on… till bar 49 where it will find the highest from bar 49 to bar 98.

     

    #149095

    with this code there’s an error since it does not like [count-1], because an array wants the content>0 (a warning message comes out). Actually I saw this issue in other cases, so apart this one I think it is interesting to know the reason.

    I solved the issue by putting before the array an “if”

    if Count>0 then

    $MyBar[Count – 1] = BarIndex[i]

    etc

    but I found it a little bit odd, because it doesn’t change the value of count itself, it is just a sort of check.

    Your comment about that would be very appreciated

    thanks

    #149096

    There’s no issue with COUNT.

    The issues are in my code, since I coded it incorrectly and I could not test it.

    The two correct versions (tested), you can remove RETURN…., I used it just to test the code:

     

     

    #149098

    yes you are right your code is correct and it works. Still I don’t understand why my version above does not work and the message “a positive parameter is expected with $hvol” comes out.

    Because in my opinion both codes are equal for the technical point of view.

    #149105

    That’s because the count is not increased when ELSE is executed.

    Remove line 10 and add this one between lines 5 and 6:

     

    #149117

    I’m lost … can you post ITF definitive version 10.3? thank you so much

    #149123

    The last correct version for v10.3 is the one I posted at https://www.prorealcode.com/topic/find-the-first-3-highest-volume-bars-in-a-specific-period/#post-149096.

     

    1 user thanked author for this post.
Viewing 15 posts - 1 through 15 (of 15 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login