Tradingview – Volume Profile With Lower Time-frame Data

In this post, we are going to take a look at creating a simple volume profile indicator on Tradingview. The indicator will attempt to import and categorize volume from a lower time-frame to give you a better picture of buying and selling volume on an upper time-frame.

The indicator will not beat the excellent volume profile tools available on the Pro subscription. However, it will provide a little more information that is currently available to free users. Additionally, we will be making use of user-created functions and the security()call in an interesting way that can be replicated for other purposes.

Volume Profile

The indicator shall attempt to do the following:

  • Look at a lower time-frame. E.g 5 minutes when we are on a 1-hour chart.
  • Create a function to loop through through candles and make an assessment.
  • If the candle it closed up, the volume will be categorized as buying volume. Conversely, if it closed down, the volume will be categorized as selling volume
  • The function will then be passed to the security() function to run on a lower timeframe.
  • All buying volume and selling volume from the lower time-frame shall be summed and displayed on the main chart.

It is important to note that this indicator will not give you genuine buying or selling volume. It simply follows the assumption that if price closed up, there must have been more buyers than sellers and if it closed down we assume the opposite.

The Code

Code Commentary

The whole indicator relies on making use of a nifty little feature in the security()function which allows you to pass any function to it. That function is then executed on the time-frame of the security and the results returned. It is like running a script within the script!

Usually, you might see people using an sma()call or some other built-in function. However, we can also pass our own functions in here too! The only limitation is that the function needs to return a single value. That is why the buying_volumeand selling_volumehave been broken up in the code.

Speaking of functions, if you are new to pinescript and need a primer on creating functions, see this tutorial for more information.

Lower Time-Frame Bars

In order to use this indicator, users will need to calculate how many lower time-frame bars are contained in the time-frame on the main chart. So for example, the default settings are configured for the indicator to be run on the 1H chart. As a result, we need to set the “Bars on Lower Timeframe” input to 12. This is because there are 12 x 5-minute bars in 60 minutes.

Of course, it would be ideal to automate this for simplicity but that appears to be quite challenging. If any readers know of a good method to do this, please post it in the comments section below.

5 – Minute Default

A default lower time-frame setting of 5 minutes is used in the indicator. This is because bars on the 1-minute timeframe are often combined/consolidated when there is no price action. Since we are simply looping through x number of bars on the lower time-frame, this can cause a problem when the bars are consolidated. You can see this easily for yourself by plotting the difference between timeandtime[1]. Let’s take a look.

Here is the output from the 1-minute chart.

We can see that there are many periods when one bar actually represents 2 or more minutes! However, if we move to the 5-minute chart, the output is much more consistent.

So the takeaway is to look at the instrument you are trading and find the lowest time-frame with limited consolidated bars to achieve the best results.

On the Charts

Fire up the indicator and this is what you should see:

The chart will display up to 3 columns. A green column for buying volume, a red column for selling volume and finally, a black column for balanced volume. Balanced volume is where neither the buyers or sellers were in control.

Verification

Just to be sure the indicator is working, we can verify the output by checking that the total of the individual bars matches the higher timeframe.

As we can see in the chart, the values add up correctly. Also, we can see there was a small amount of volume where neither buyers or sellers were in control. As mentioned above, we categorize this as a balanced volume and measure it with a black bar. To double check this, we can take a look at the 5-minute timeframe side by side.

And that is all folks!

Support The Site!

If you like this article and are thinking to become a Tradingview subscriber, you can support the site by clicking on the affiliate link below before signing up!

https://tradingview.go2cloud.org/SHpB