Page 1 of 1

Comparing volume bars

Posted: Sun Mar 06, 2022 5:00 pm
by joecjr
Hi everyone. This is my first post. I am quickly working through all the training and trying to get some useful code built. I could use some help from the community. I am trying to identify a pattern for volume only:

- Group volume bars into groups of 3 (3 consecutive bars, starting from most recent closed bar)
- Check if most recent closed volume bar closed higher than the previous volume bar
- Check if the volume bar 3 bars ago closed higher than the volume bar 2 bars ago
- In other words, High-Low-High pattern
- I want to mark the middle bar
- I want this pattern to repeat in groups of 3, looking back in time on the chart

Clearly, I am not succeeding. This is what I have so far:

Code: Select all

//@version=5
indicator("volume detector")

highLowHigh= barstate.isconfirmed and (volume[1] > volume[2]) and (volume[3] > volume[2] -1)

bgcolor(color=highLowHigh ? color.green[2] : na)

This community is outstandling. I am so thankful we have something like this.

Re: Comparing volume bars

Posted: Wed Mar 09, 2022 9:58 am
by processingclouds
Hey, try the following code:

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("Volume Detector","VD", overlay=true)

// Check if pattern is High Low High
HLH = volume[2] > volume[1] and volume[1] < volume

// Color background with 50% transparency , and shift it left by 1 on middle 
bgcolor(HLH ? color.new(color.green,50) : na, -1)


Re: Comparing volume bars

Posted: Wed Mar 09, 2022 4:30 pm
by joecjr
That is so much more elegant. I am happy that I was in the "ballpark", but I really appreciate the help.