Volume/Market Profile

SamRecio Aggiornato   
Volume/Market Profile is a 2 in 1 Volume Profile and Market Profile Indicator.
This indicator is my own calculations for compiling a volume profile and market profile.
The profile is progressively calculated live as the chart develops.
I have made use of both Boxes AND Lines to allow me to display a finer granularity profile by displaying up to twice the max amount of lines allowed in tradingview.
I have spent a lot of time to make sure the values are getting appended exactly as intended so that I can assure this profile is operating as precisely as possible within the limitations of the data available.
To make my calculations easier to use in other places, I have made my volume profile a function that can be extracted and used whenever you need values from a volume profile.
Feel free to read through the script if you don't understand how this profile is developed. I have made a commentary of my volume profile function to help you understand what exactly happens to compile the profiles.
As mentioned before, This indicator doubles as a market profile. To view both at the same time you will need to add the indicator on your chart twice.
I have built in comprehensive customizations to allow you to display your profiles however fits your needs.

Timeframe: The aggregation period for profiles, to see a 1 week profile, change the timeframe to 1 week.
Note: You can add custom timeframes by adding a custom timeframe in your chart timeframe dropdown menu. When you add timeframes in this area, they appear as options within indicators with the timeframe input.
Sensitivity: Allows for greater or less granularity changes. The calculation method for granularity automatically changes depending on the range of your chart.
Note: Multiply this value by 100 and that will be the max range (in ticks) of your price before the indicator automatically adjusts to make the profile less granular. (ex. If price ranges $1, and 1 tick is $0.01, granularity will be 0.01 with a sensitivity of 1+)
Value Area %: % of total volume to display as the value zone. (_% of total profile values are contained within the value zone)
Calculate as Market Profile: Uses a 1 Instead of the candle volume, to display a Market Profile. (If selected POC -> TPOC)
Display Size: Sets the # of bars from the profile axis to the profile's max value. If set negative, profile will be displayed left of axis, if positive, profile will be displayed to the right of the axis.
Display Offset: Sets the # of bars in front(or behind) the current chart bar to set the axis of the profile. If negative, the axis will be to the left of the current chart bar, if positive the axis will be right of the current chart bar.
Display Historical POC/VAH/VAL: Choose to display historical poc,vah,val lines.
Colors: I'm not explaining colors.
Note di rilascio:
-Added a new error condition. Incase your Profile Timeframe is too large for the chart you're on. (ex. 5min timeframe trying to look at a 12 month profile) The chart doesn't have that data on such a low timeframe, so now you'll get an error.
Note di rilascio:
-Added an option to display the current poc/vah/val as lines across your bars instead of only on the profile.
- Moved the "Display historical..." setting into its own group with the newly added option, now under "Additional Data Displays"
Note di rilascio:
MAJOR UPDATE: Notes first then more details below.
1. Lookback Calculation Added
2. High/Low Volume Area Added
3. Lowest Volume Area Removed
4. Progressive VP Calc minor Bug fix

In my examples I will talk about a daily volume profile on a 5 minute chart.
1) I have created a lookback volume profile calculation that translates your requested timeframe into the proper number of bars and then displays a profile created from the # of lookback bars.
The lookback profile does not reset on ever new day, rather it looks at how long the previous day was and displays a profile for that length back of data, by doing this, your lookback profile will always be relevant to the data you want to see, and all the bar conversions are done behind the scenes.
The calculation was created with different sessions, and chart types in mind. It does not (by default) use a static lookback bars number, it will determine the proper amount of bars to view a profile at the length of the time you requested. If you look at a 1 day profile on a 5 min RTH chart you will typically get a 77 bar profile, except if you were to switch to the ETH version of the chart, you will get a 191 bar profile, this is due to the the dynamic lookback bar calculation style, It is still giving you a profile from yesterday at the same time.
This method would fail if it were only checking the previous day's length of bars and updating on every new day with a new lookback. If there were a short day, the profile on the following day would start phasing out data before the day is over. Because of this, I am checking the length of the the current day, as well as the length of the previous day and taking the greatest of the 2 updating on every bar, to give you an entire day's profile even after a short day.
After identifying this I realized a contrary argument, "If I input 4H, I want to see a profile from the last 4 Hours".
Because of this, The lookback calculation uses a different determination method for intraday timeframe requests, vs DWM timeframe requests.
It works like this:
If you use a timeframe for a lookback profile that is 1 day or larger, the lookback will be determined based on the number of Days, Weeks, Months, Etc. requested. These lengths can change depending on the length of the D/W/M.
If you use a timeframe for a lookback profile that is less than 1 day, you will see that amount of time in bars back. A 240min(4Hour) profile on a 5 min chart will ALWAYS be 48 bars.

If you want to use a lookback calculation of a specific number of bars, you can override the lookback calculation at the bottom of the settings.

2. You can now choose to color zones with High/Low volume relative to the POC's volume.
Example: Low Volume % = 10; will color every node with volume equal-to or Less than 10% of the POC's volume.
Example: High Volume % = 90; will color every node with volume equal-to or Greater Than 90% of the POC's volume.

3.With the addition of High/Low volume zones, the least volume area was no longer necessary .

4.Previously the VP was including data from the starting bar, but then writing to the same indexes in same bar. It ended up only minorly effecting the entire profile, but I noticed it when comparing the 2 calculations.
Simple terms: The previous Progressive calculation was including double data for the first bar, no longer.

Please feel free to ask any questions you may have about this update, I have also included tooltips in the Settings for quick references of this data.
Note di rilascio:
Identified an error causing a slight inaccuracy in profile calculation.
This issue was solved by moving the z_point variable definition from outside, to inside the "Input Values" loop(Line 101)
Note di rilascio:
Removed High/Low Volume % Zones
Replaced with High/Low Volume Nodes via. Cluster Identification

My Volume Cluster ID method can be easily explained as vertical Pivot Points through out the Profile.

Determination method for normal Pivot points: Pick a point, Check bars left, Check bars right, If nothing else is higher (or lower), mark it as a pivot point.
Determination method for VMP: Pick a point, Check bars down, Check bars up, it the point is the highest (or lowest) point OR within the allowed amount of tolerance from the highest or lowest point, mark it as a node point.

"Analysis width" is the specific number of indexes to check up and down
"% Tolerance" (signified as only '%' in the settings) widens or narrows the included values based on % from the highest (or lowest) in the node
Note di rilascio:
Optimization update + Some Changes

Volume Node Cluster detection now uses % of profile width as the determination method for HVNs & LVNs, this provides more consistent nodes regardless of the granularity of the profile.
The settings do basically the same as before but the "Analysis Width %" now uses "% width of profile" vs previously "# of profile lines"
Below is a Screenshot of what the new Volume Node settings look like and what they adjust.

No longer Rounding Volume data. I found that on Cryptocurrencies the profile was giving inaccurate values due to the divided volume getting rounded to a whole number.
In stocks this made no difference, but since the volume type is different in crypto it is a noticeable improvement to accuracy.

- Slight optimization, to get the most rows displayed as possible; the script is now checking for <1 values(values that would otherwise not display) and not drawing them.
- "Display" changed to "Extend" Current POC/VAH/VAL now goes to the profile instead of stopping at the last chart bar
Note di rilascio:
Volume Node Cluster ID Improvement!
- Local volume clusters are now merged into 1 group, to solve areas with many small lines when the entire area should be highlighted.
Technical Note: This version is merging by a 2% (profile width) range, this option is not editable in the UI but I may include it in the future. If you can't wait, it can be changed on line 203.
- Depth % REMOVED, My new method compares the points to the profile's local average to determine what to include and not include in the volume node.
- Added the Option to disable Volume Node ID, If you don't want the volume nodes highlighted.
Note di rilascio:
Latest Graphic to help understand the update:
Note di rilascio:
HUGE (Technical) UPDATE!!! No More Sensitivity! Rolling POC Added!

The entire indicator was Re-Worked to take advantage of Pinescript Maps, these data structures allow me to store volume data directly to price levels rather than needing to parse through an array.
Additionally, Maps simplify the profile-making process by not needing to check for expanding the profile up or down, since we are storing to price, we are simply adding a new "key" to the map.

General Notes:
- Removed Sensitivity input value, Every profile is at full granularity if capable. If not, it is scaled to 1000 rows.
Since I am using lines AND boxes, the max capable of display is 500 of each. I see no reason to compile a finer profile than can be seen by the user, so it is limited to 100 rows.
- Removed "Display Historical POC/VAH/VAL", this is replaced by "Rolling POC/TPO" and "Rolling VAH/VAL" Options
- Added "TPO" label when using market profile
- Added Tooltips for POC/VAH/VAL labels
- VMP now functions better on Crypto and Forex Charts than in previous versions.

Technical Notes:

- Removed FULL Notation, Notes can be found in the older version for anyone interested. Some points are still included.
- Developing Timeframe Profiles have been switched to a "Lookback" style calculation. By doing this, I am able to calculate the exact tick size needed for each profile. This is how I achieve a constant full granularity or 1000 rows.
- Values for granularity and values on tooltips are rounded to the same number of decimal places as the chart's minimum tick(mintick) value. (ex. Spy mintick = 0.01 -> all values are rounded to 2 decimals). It is possible for the profile to calculate in values that are more decimal places than the mintick, however the labels will only read to the nearest mintick.
- Historical profiles use less granularity relative to the distance from the current bar. This speeds up calculations and in my testing has shown negligible differences.
- If not displaying any "Rolling" Values, the script does not bother to calculate a profile on every bar, and instead only calculates on the current bar.
- POC now only takes the first(lowest) MAX value of the profile, this is due to changes to the POC calculation in accordance with the new Map method.
- "Extend" lines now do not draw new lines and instead only change the points of the current POC/VAH/VAL lines. This ensures that I can display 1000 at all times for the whole profile.
- Added Alternation of Lines and Boxes to provide a more consistent profile look.
- Profile Calculations are no longer in a function, this is for speed and consistent look of the code. Since Maps now allow a profile to be compiled in (as little as) 3 lines, extracting the calculations to use in other places are a lot simpler in this new version.
- Due to the "Lookback" style calculations, I no longer need a reference period to gauge tick size. Because of this, the profile can be calculated some charts that it currently could not, since the chart did not contain 2 full periods.

Note di rilascio:
MAJOR Update w/ Huge Improvements:
Longer Lookbacks, Less errors.

- Data Management was re-structured, no longer using historical references.
This Majorly improves performance all around, longer lookbacks, and less errors.
NOTE: Rolling Value calculations are more limited than typical (last bar) profile calculations. This is due to the heavy processing that it takes to acquire them for all historical data. Because of this, it is more likely to find errors when working with the rolling values on larger lookbacks.

- Due to the farther lookback capabilities I have implemented a warning label for when you are requesting farther than the chart has. Instead of throwing an error for the entire indicator, it will now display a MAX bar profile. This will display a profile of every bar on your chart and notify you of the start date of your data.
This can be used to view a full chart history profile if you wanted to do that.

- If viewing a profile 5k bars or larger, the "extend" lines will extend all the way left, instead of to the start of the calculation point.

- Solidified POC calculation, POC is now calculating as the Highest volume that is closest to the profile price average.

- Optimized . . . a lot.

This is it.
Note di rilascio:
-Fixed coloring Error.
Note di rilascio:
Lookback length bug fix.

Script open-source

Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.

Vuoi usare questo script sui tuoi grafici?