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
- This topic has 14 replies, 3 voices, and was last updated 4 years ago by robertogozzi.
-
-
10/24/2020 at 5:57 PM #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
10/25/2020 at 9:28 AM #148380There you go (not tested):
1234567891011121314151617HiVol = (Volume = highest[50](Volume))i = 0Count = 0While i < 50If HiVol[i] ThenCount = Count + 1If Count = 1 thenBar1 = Barindex[i]Elsif Count = 2 ThenBar2 = Barindex[i]Elsif Count = 3 ThenBar3 = Barindex[i]BreakEndifEndifi = i + 1Wendaf 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:
12345678910111213HiVol = (Volume = highest[50](Volume))i = 0Count = 0While i < 50 //scan the last 50 barsIf Volume[i] = HiVol[i] ThenCount = Count + 1$MyBar[Count - 1] = BarIndex[i]If Count = 3 Then //retrieve the last 3BreakEndifEndifi = I + 1Wend$MyBar[..], from 0 to 2, will retain values if COUNT > 0.
10/25/2020 at 10:23 AM #148384Ciao 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:
123456789101112<span class="keyword">if</span> (a <= b) {<span class="keyword">if</span> (a <= c) {<span class="keyword">if</span> (b <= c) printf(<span class="string">"%d %d %d\n"</span>, a, b, c);<span class="keyword">else</span> printf(<span class="string">"%d %d %d\n"</span>, a, c, b);} <span class="keyword">else</span> printf(<span class="string">"%d %d %d\n"</span>, c, a, b);} <span class="keyword">else</span> {<span class="keyword">if</span> (b <= c) {<span class="keyword">if</span> (a <= c) printf(<span class="string">"%d %d %d\n"</span>, b, a, c);<span class="keyword">else</span> printf(<span class="string">"%d %d %d\n"</span>, b, c, a);} <span class="keyword">else</span> printf(<span class="string">"%d %d %d\n"</span>, c, b, a);}}Sorry for the programming language but it is just to explain.
Grazie per l’aiuto
Roberto
10/25/2020 at 1:13 PM #148398HiVol = (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,
10/25/2020 at 2:30 PM #148410Hello
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] Thenyou 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?10/25/2020 at 2:39 PM #148411You are right, that line ahould read:
1If HiVol[i] Then10/25/2020 at 2:43 PM #148412Counter i always starts from 0 up to 49. In that range there should be at least one highest volume, sometimes 2 or 3.
10/25/2020 at 2:51 PM #148416Sorry 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.
10/25/2020 at 4:16 PM #148422Yes, 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.
10/31/2020 at 6:43 PM #14909512345678910111213HiVol = (Volume = highest[50](Volume))i = 0Count = 0While i < 50 //scan the last 50 barsIf Volume[i] = HiVol[i] ThenCount = Count + 1$MyBar[Count - 1] = BarIndex[i]If Count = 3 Then //retrieve the last 3BreakEndifEndifi = I + 1Wendwith 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
10/31/2020 at 7:40 PM #149096There’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:
v1112345678910111213i = 0Count = 0While i < 50 //scan the last 50 barsIf Volume[i] = highest[50](Volume[i]) THENCount = Count + 1$MyBar[Count - 1] = BarIndex[i]If Count = 3 Then //retrieve the last 3BreakEndifEndifi = I + 1Wendreturn Count AS "Count",0 AS "0",1 as "1",2 as "2",3 AS "3"v10.31234567891011121314151617i = 0Count = 0While i < 50If Volume[i] = highest[50](Volume[i]) ThenCount = Count + 1If Count = 1 thenBar1 = Barindex[i]Elsif Count = 2 ThenBar2 = Barindex[i]Elsif Count = 3 ThenBar3 = Barindex[i]BreakEndifEndifi = i + 1Wendreturn Count AS "Count",0 AS "0",1 as "1",2 as "2",3 AS "3"10/31/2020 at 8:27 PM #149098123456789101112131415numbar = 60i = 0count = 0AvgVolume = Average[10](volume)while i < numbarif volume[i] > AvgVolume thencount = count + 1$hvol[count-1] = volume[i]else$hvol[count-1] = 0endifi =i + 1wendreturnyes 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.
10/31/2020 at 10:23 PM #149105That’s because the count is not increased when ELSE is executed.
Remove line 10 and add this one between lines 5 and 6:
1$hvol[count] = 011/01/2020 at 8:33 AM #149117I’m lost … can you post ITF definitive version 10.3? thank you so much
11/01/2020 at 10:01 AM #149123The 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.
-
AuthorPosts
Find exclusive trading pro-tools on