joecjr
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: March 5th, 2022
Contact: TradingView Profile

Comparing volume bars

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.

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Comparing volume bars

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)


joecjr
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: March 5th, 2022
Contact: TradingView Profile

Re: Comparing volume bars

That is so much more elegant. I am happy that I was in the "ballpark", but I really appreciate the help.

Return to “Pine Script Q&A”