TradingView
Fr3d0C0rl30n3
31 ott 2021 22:51

Fr3d0's Volume Profile Visible Range 

Bitcoin / TetherUSBinance

Descrizione

Low level implementation
At the core of VPVR there’s a concept called “bucketization”.

Question: what is bucketization?
Answer: bucketization consists of identifying metrics with high predictive power and combine them appropriately.

I think this is a problem of bucketization because what the VPVR does is to take a price range, divide it into buckets and fill them up with the volume that was produced in each bucket’s range over the given period.

The more we divide our price range the finer the resolution, but also the less significant each bucket will become.

The steps are:
1. Get the price range with min and max over the give period;
2. Divide the range into buckets;
3. Loop over each candle of the given period and proportionally assign volume to one or more bucket.

Question: how to assign volume to buckets?

Answer: we need to calculate the right amount to add to each bucket for each candle. If 20% of a candle lies on a bucket then that bucket needs to have 20% of the volume of that candle, the rest 80% belongs to other buckets.

To get the percentage of a candle on a given bucket we have to find the price range of the candle contained within the bucket, then divide that amount by the entire length of the candle.

How to bucketize

Question: what are the formulas of A, B, C and Target respectively?

Answer:
- A = Max(candle_high, bucket_top) - Min(candle_low, bucket_bottom);
- B = Max(candle_high, bucket_top) - Min(candle_high, bucket_top);
- C = Max(candle_low, bucket_bottom) - Min(candle_low, bucket_bottom);
- Target = A - B - C.

Now that we now how to calculate the price range belonging to each bucket we need to calculate a percentage of volume to fill the bucket with.
The formula is trivially simple:
Volume * Target / (candle_high - candle_low).

Question: can we distinguish between buy volume and sell volume? If so, how?

Answer: yes we can and the following paragraph will teach you how.

Put it simply we can use the difference between the extremes of a candle (low and high) and its close price to get the buy and sell volumes.
The formulas for that are:
- Buy volume = Volume * (close - low) / (high - low);
- Sell volume = Volume * (high - close) / (high - low).

I know this is rather simplicistic but it makes sense.

Closing thoughts
This script is a working progress and I’m going to give more details if necessary, just let me know in the comments down below.

Note di rilascio

Add distance from last candle as requested by TradingView's users

Note di rilascio

Fix last added feature

Note di rilascio

Clean up the drawings on every tick, so there's only one instance of the indicator at any given moment

Note di rilascio

Add color inputs, now the user can customize colors for lines and bars
Commenti
jkislow
What are the volume candles that extend the opposite way? I figured it may be the POC but I’m getting several extending to the left.
TMK2
Hi, @Fr3d0C0rl30n3

This is great! If you get the chance, kindly add a POC and Value Area.

It is that last bit of magic that the indicator is missing. Other than that, this is great.
Tepels
how do i pin it to right side? i did in options but it stays left
bdubya13000
Thanks for this, I know nothing about pine, so I was wondering if there was a way to get the bars to extend left instead of right?
Fr3d0C0rl30n3
@bdubya13000, I could do that but I don't know how to pin the indicator on the right side of the screen, so I won't do it! Sorry :)
helloktity
Hello, thank you very much for your indicator, but I encountered a problem in the process of using it. Whenever a new bar is generated, the indicator moves one bar to the right, but the histogram of the previous bar There is no automatic deletion, so there will be two histograms, which will overlap one part. Due to comment restrictions, I am very sorry that I cannot post a screenshot.
Fr3d0C0rl30n3
@helloktity, I've just fixed it! Sorry for the delay but I was not trading for quite a while...
paschapavlovski
leftoriented vpvr based on fr3d0's
Was it your script ? It's blocked. Could you share his code?
Fr3d0C0rl30n3
@paschapavlovski, my script is that you see here. :)
botanikchannel
Dear Fr3d0C0rl30n3,

I like your Idicator pretty much.

I think I get this right, the green bar and the red bar shows the buyers/sellers volume at a certain price?

I think it would be interessing to see the ratio, meaning a figure next to the bars like 0,5 if volume was equal.
Or 0,7 ir 0,7 is buyer volume. Alternative would be a line through the median on every bar, I believe that would
show 50% of every bar.

Best Regards
Altro