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.
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.
//@version=3 study("Intra-bar Volume", overlay=false) lower_tf = input("5", title='Lower Timeframe to Assess') bars_in_tf = input(12, title='Bars of lower Timeframe')-1 // -1 because we count from zero in the loop balanced_volume(range)=> vol = na for i = 0 to range if open[i] == close[i] vol := na(vol) ? volume[i] : vol + volume[i] vol buying_volume(range)=> vol = na for i = 0 to range if open[i] < close[i] vol := na(vol) ? volume[i] : vol + volume[i] vol selling_volume(range)=> vol = na for i = 0 to range if open[i] > close[i] vol := na(vol) ? volume[i] : vol + volume[i] vol lower_buy_vol = security(tickerid, lower_tf, buying_volume(bars_in_tf)) lower_sell_vol = security(tickerid, lower_tf, selling_volume(bars_in_tf)) balanced_vol = security(tickerid, lower_tf, balanced_volume(bars_in_tf)) plot(balanced_vol, style=columns, color=black, transp=70, title='Balanced Volume') plot(lower_buy_vol, style=columns, color=green, title='Buying Volume') plot(lower_sell_vol, style=columns, color=red, transp=50, title='Selling Volume')
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
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
time. 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.
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!
Find This Post Useful?
If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.
Backtest Rookies is a registered with Brave publisher!
Brave users can drop us a tip.
Alternatively, support us by switching to Brave using this referral link and we will receive some BAT!
Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up!