0% found this document useful (0 votes)
92 views4 pages

VWAP and Volume Profile Indicator

This document is a TradingView Pine Script for a custom indicator that combines the Volume Weighted Average Price (VWAP) with a Volume Profile anchored on a daily basis. It includes various settings for customizing the VWAP, bands, and volume profile display, allowing users to adjust parameters such as the anchor period, band multipliers, and volume type. The script calculates and plots the VWAP, its bands, and the volume profile with options for displaying the Point of Control and Value Area.

Uploaded by

rameshmca06
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views4 pages

VWAP and Volume Profile Indicator

This document is a TradingView Pine Script for a custom indicator that combines the Volume Weighted Average Price (VWAP) with a Volume Profile anchored on a daily basis. It includes various settings for customizing the VWAP, bands, and volume profile display, allowing users to adjust parameters such as the anchor period, band multipliers, and volume type. The script calculates and plots the VWAP, its bands, and the volume profile with options for displaying the Point of Control and Value Area.

Uploaded by

rameshmca06
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=6

indicator(title="VWAP + Volume Profile (Daily Anchor)", shorttitle="VWAP+VP",


overlay=true, max_bars_back=5000, max_lines_count=500)

// ——————————————————————— VWAP SETTINGS ———————————————————————


hideonDWM = [Link](false, "Hide VWAP on 1D or Above", group="VWAP Settings")
anchor = [Link]("Session", "Anchor Period",
options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century",
"Earnings", "Dividends", "Splits"],
group="VWAP Settings")
src = [Link](hlc3, "Source", group="VWAP Settings")
offset = [Link](0, "Offset", minval=0, group="VWAP Settings")

// Force Daily Anchor (as requested)


isNewPeriod = [Link]("D")

// Bands
calcModeInput = [Link]("Standard Deviation", "Bands Calculation Mode",
options=["Standard Deviation", "Percentage"], group="Bands Settings",
tooltip="Standard Deviation uses stdev; Percentage uses % of VWAP")
showBand_1 = [Link](true, "", inline="band1", group="Bands Settings")
bandMult_1 = [Link](1.0, "Multiplier #1", inline="band1", step=0.5, minval=0,
group="Bands Settings")
showBand_2 = [Link](false, "", inline="band2", group="Bands Settings")
bandMult_2 = [Link](2.0, "Multiplier #2", inline="band2", step=0.5, minval=0,
group="Bands Settings")
showBand_3 = [Link](false, "", inline="band3", group="Bands Settings")
bandMult_3 = [Link](3.0, "Multiplier #3", inline="band3", step=0.5, minval=0,
group="Bands Settings")

// ——————————————————————— VOLUME PROFILE SETTINGS ———————————————————————


vp_use_visible = [Link](false, "Use Visible Range", group="Volume Profile")
vp_lookback = [Link](200, "Fixed Lookback Bars", minval=10, maxval=3000,
group="Volume Profile")
vp_num_bars = [Link](200, "Number of VP Bars", minval=10, maxval=490,
group="Volume Profile")
vp_thickness = [Link](1, "Bar Thickness", minval=1, maxval=30, group="Volume
Profile")
vp_len_mult = [Link](20, "Length Multiplier", minval=1, maxval=50, group="Volume
Profile")
vp_right_offset = [Link](70, "Right Offset", minval=0, maxval=400, group="Volume
Profile")
vp_volume_type = [Link]("Both", "Volume Type", options=["Both", "Bullish",
"Bearish"], group="Volume Profile")
vp_bar_color = [Link]([Link]([Link], 50), "VP Bar Color", group="Volume
Profile")

// PoC
show_poc = [Link](true, "Show Point of Control (PoC)", group="Point of
Control")
poc_color = [Link]([Link], "PoC Line Color", group="Point of Control")
poc_thick = [Link](1, "PoC Thickness", minval=1, maxval=30, group="Point of
Control")

// Value Area
show_va = [Link](true, "Show Value Area", group="Value Area")
va_percent = [Link](68, "VA %", minval=5, maxval=95, group="Value Area")
va_bar_color = [Link]([Link], "VA Bar Color", group="Value Area")
show_va_lines = [Link](true, "Show VAH/VAL Lines", group="Value Area")
va_line_thick = [Link](1, "VA Lines Thickness", minval=1, maxval=20,
group="Value Area")

// ——————————————————————— VWAP CALCULATION ———————————————————————


float vwapValue = na
float upper1 = na
float lower1 = na
float upper2 = na
float lower2 = na
float upper3 = na
float lower3 = na

if not (hideonDWM and [Link])


[_vwap, _stdevUpper, _] = [Link](src, isNewPeriod, 1)
vwapValue := _vwap
float stdev = _stdevUpper - _vwap
float bandBasis = calcModeInput == "Standard Deviation" ? stdev : _vwap * 0.01

upper1 := _vwap + bandBasis * bandMult_1


lower1 := _vwap - bandBasis * bandMult_1
upper2 := _vwap + bandBasis * bandMult_2
lower2 := _vwap - bandBasis * bandMult_2
upper3 := _vwap + bandBasis * bandMult_3
lower3 := _vwap - bandBasis * bandMult_3

// Plot VWAP
plot(vwapValue, "VWAP", color=#2962FF, linewidth=2, offset=offset)

// Plot Bands
p1u = plot(upper1, "Upper Band 1", color=[Link], offset=offset,
display=showBand_1 ? [Link] : [Link])
p1l = plot(lower1, "Lower Band 1", color=[Link], offset=offset,
display=showBand_1 ? [Link] : [Link])
fill(p1u, p1l, [Link]([Link], 95), title="Band 1 Fill",
display=showBand_1 ? [Link] : [Link])

p2u = plot(upper2, "Upper Band 2", color=[Link], offset=offset,


display=showBand_2 ? [Link] : [Link])
p2l = plot(lower2, "Lower Band 2", color=[Link], offset=offset,
display=showBand_2 ? [Link] : [Link])
fill(p2u, p2l, [Link]([Link], 95), title="Band 2 Fill",
display=showBand_2 ? [Link] : [Link])

p3u = plot(upper3, "Upper Band 3", color=[Link], offset=offset,


display=showBand_3 ? [Link] : [Link])
p3l = plot(lower3, "Lower Band 3", color=[Link], offset=offset,
display=showBand_3 ? [Link] : [Link])
fill(p3u, p3l, [Link]([Link], 95), title="Band 3 Fill", display=showBand_3 ?
[Link] : [Link])

// ——————————————————————— VOLUME PROFILE ———————————————————————


var int lookback_bars = vp_use_visible ?
[Link]((last_bar_time - chart.left_visible_bar_time) /
(timeframe.in_seconds() * 1000)) : vp_lookback

var line poc_line = na


var line vah_line = na
var line val_line = na
var array<line> vp_lines = array.new_line()
var array<float> vol_levels = array.new_float(vp_num_bars, 0)

float high_price = [Link](lookback_bars)


float low_price = [Link](lookback_bars)
float price_step = (high_price - low_price) / (vp_num_bars - 1)

// Initialize lines
if [Link]
for i = 0 to vp_num_bars - 1
[Link](vp_lines, [Link](bar_index, close, bar_index, close,
width=vp_thickness))
if show_poc
poc_line := [Link](bar_index, close, bar_index, close, color=poc_color,
width=poc_thick)
if show_va and show_va_lines
vah_line := [Link](bar_index, close, bar_index, close,
color=va_bar_color, width=va_line_thick)
val_line := [Link](bar_index, close, bar_index, close,
color=va_bar_color, width=va_line_thick)

// Scale volume to bar length


scale_vol(vol, max_vol) =>
d = max_vol / lookback_bars / (vp_len_mult / 100)
[Link](vol / d)

// Recalculate VP on last bar


if [Link]
// Reset volumes
[Link](vol_levels, 0)

// Accumulate volume per price level


for i = 0 to lookback_bars - 1
for j = 0 to vp_num_bars - 1
float level = low_price + price_step * j
bool bullish = close[i] >= open[i]
bool include = vp_volume_type == "Both" or
(vp_volume_type == "Bullish" and bullish) or
(vp_volume_type == "Bearish" and not bullish)
if include and level >= low[i] and level < high[i]
[Link](vol_levels, j, [Link](vol_levels, j) + volume[i])

// Draw VP
float max_vol = [Link](vol_levels)
int poc_idx = [Link](vol_levels, max_vol)
int x2 = bar_index + vp_right_offset

for j = 0 to vp_num_bars - 1
int len = scale_vol([Link](vol_levels, j), max_vol)
int x1 = x2 - len
float y = low_price + price_step * j
line.set_xy1([Link](vp_lines, j), x1, y)
line.set_xy2([Link](vp_lines, j), x2, y)
line.set_color([Link](vp_lines, j), j == poc_idx ? poc_color :
vp_bar_color)

// PoC Line
if show_poc
int poc_len = scale_vol(max_vol, max_vol)
line.set_xy1(poc_line, bar_index - lookback_bars, low_price + price_step *
poc_idx)
line.set_xy2(poc_line, x2 - poc_len - 10, low_price + price_step * poc_idx)

// Value Area
if show_va
float total_vol = [Link](vol_levels)
float target_vol = total_vol * va_percent / 100
int up = poc_idx, dn = poc_idx
float va_sum = max_vol

while va_sum < target_vol


float v_up = up < vp_num_bars - 1 ? [Link](vol_levels, up + 1) : 0
float v_dn = dn > 0 ? [Link](vol_levels, dn - 1) : 0
if v_up == 0 and v_dn == 0
break
if v_up >= v_dn
va_sum += v_up
up += 1
else
va_sum += v_dn
dn -= 1

// Color VA bars
for j = dn to up
if j != poc_idx
line.set_color([Link](vp_lines, j), va_bar_color)

// VAH / VAL Lines


if show_va_lines
int vah_len = scale_vol([Link](vol_levels, up), max_vol)
int val_len = scale_vol([Link](vol_levels, dn), max_vol)
float y_vah = low_price + price_step * up
float y_val = low_price + price_step * dn
line.set_xy1(vah_line, bar_index - lookback_bars, y_vah)
line.set_xy2(vah_line, x2 - vah_len - 10, y_vah)
line.set_xy1(val_line, bar_index - lookback_bars, y_val)
line.set_xy2(val_line, x2 - val_len - 10, y_val)

Common questions

Powered by AI

Offset settings allow traders to shift the VWAP and Volume Profile plots forward or backward on the timeline, which can aid in aligning these indicators with other chart elements or trading signals. Strategically changing offsets can improve the timing accuracy of predictive models or harmonize multi-indicator strategies by aligning signals across different analysis dimensions. It requires careful testing, as unintentional misalignment may misguide the analysis, leading to incorrect trading decisions .

The VWAP indicator calculates a volume-weighted average price, helping traders identify average price levels over a specified period. It integrates with volume profile settings by anchoring to different periods (e.g., Session, Week, Month), which allows for detailed volume analysis within these periods. Through its settings, users can display bands calculated with standard deviation or percentage, further enhancing the analysis by showing areas of volume concentration around the VWAP. The volume profile aspect visualizes traded volume at different price levels, highlighting the Point of Control (PoC) and Value Areas, which provide insight into price levels where significant trading occurred .

Adjusting the 'Number of VP Bars' affects the granularity of the Volume Profile. More bars offer finer detail of volume distribution across price levels, beneficial for detailed analysis of price movements and short-term trading. Conversely, fewer bars provide a coarser view that may blend data but could help in identifying stronger support and resistance zones for longer-term analysis. The decision balances the need for detail against clarity, where excessive granularity could overwhelm with noise, while too few bars might understate critical levels .

The 'Hide VWAP on 1D or Above' setting allows traders to declutter their charts by hiding the VWAP line when analyzing longer time frames (daily or above). This can be strategically used when higher timeframe analysis focuses on broader trends rather than intraday trading metrics. By removing VWAP visualizations, traders can concentrate on other indicators or patterns that matter more for long-term decisions, which could aid in a clearer understanding of significant trend directions without the noise of short-term data .

The 'Point of Control' (PoC) in Volume Profile analysis represents the price level where the highest volume of trading occurred during the specified period. It's identified by calculating volumes at different price levels and determining which level has the maximum volume. The PoC is critical for identifying the level of highest market activity, which can act as a strong support or resistance point .

Selecting the anchor period in VWAP settings affects the resolution and applicability of the analysis. Different periods, such as Session, Week, or Month, allow traders to tailor the VWAP calculation to align with their trading timeframe. A shorter anchor period can provide more immediate insights, which might be suitable for day traders, while longer periods are beneficial for swing or position traders looking at broader trends. The choice of period impacts how market trends and possible reversals are perceived, influencing trading decisions .

Choosing a 'Fixed Lookback Bars' setting specifies a constant range of historical data for volume analysis, regardless of the visible chart area. This stationary approach ensures that analysis remains consistent when comparing different periods or conducting backtests. It can provide predictable volume insights, useful for traders who rely on historical consistency. However, it might neglect recent market changes visible with dynamic scaling since the lookback doesn't adjust to current volatility or trend shifts, potentially affecting the relevance of the analysis to ongoing conditions .

The Value Area percentage setting determines what fraction of total traded volume is highlighted around the PoC. Typical settings like 68% align with standard deviation usage, but varying this setting impacts the breadth of price area shown as significant. A smaller percentage can condense the visible Value Area, emphasizing only the most traded prices, while a higher percentage broadens it, displaying more price levels considered important by market participants. This impacts trader decisions by defining levels deemed supportive or resistive, guiding entry and exit strategies .

The 'Use Visible Range' feature adjusts the Volume Profile analysis to the range currently visible on the chart, which dynamically updates as the user zooms or scrolls. This allows for targeted analysis of particular market phases or recent price action without interference from irrelevant historical data. It enhances the precision of the volume analysis by focusing on the current context, aiding traders in identifying immediate actionable insights, which can be crucial for short-term strategies .

Band settings enhance VWAP's effectiveness by providing visual boundaries that indicate standard deviations or percentages from the VWAP line. This allows traders to observe potential overbought or oversold conditions. The bands act as dynamic support and resistance levels, helping to identify price reversal opportunities. By adjusting the settings, such as band multipliers and calculation modes, traders can fine-tune the analysis to suit different market conditions .

You might also like