本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga
//@version=6
indicator("VWAP Volume Profile [BigBeluga]", overlay = true, max_bars_back = 500, max_boxes_count = 500)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
int period = input.int(250)
int offset = input.int(10)
int bins = input.int(50)
string poc_type1 = input.string("+/-VWAP", "POC", ["+VWAP", "-VWAP", "+/-VWAP"])
int poc_type = poc_type1 == "+VWAP" ? 1 : poc_type1 == "-VWAP" ? 2 : 3
color up_col = input.color(#42bda8, "+/-", inline = "col")
color dn_col = input.color(#ffb950, "", inline = "col")
color bgcol = input.color(color.rgb(5, 38, 82, 80), "", inline = "col")
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
series float vwap = ta.vwap(close)
color vwap_col = vwap > vwap[5] ? up_col : dn_col
series float src = vwap
get_vol(vwap)=>
if ta.cum(volume) < 1 and barstate.islast
label.new(bar_index, hl2, "No Volume Data Provided", size = size.huge)
vol = volume
sum = ta.highest(vol, 1000)
volume_ = src > src[2] ? vol : -vol
volume_ / sum*20
get_grid(period, bins)=>
H = ta.highest(period)
L = ta.lowest(period)
step = (H-L) / bins
[H, L, step]
vwap_profile(src, period, bins)=>
[H, L, step] = get_grid(period, bins)
float volume_ = get_vol(vwap)
box pos_poc = box(na)
box neg_poc = box(na)
color bg_col = color(na)
var vp = array.new<box>(bins, box(na))
volume_1 = array.new<int>(bins, 0)
volume_2 = array.new<float>(bins, 0.)
int n = bar_index + offset
if barstate.islast
for i = 0 to vp.size()-1
float low_ = L + step * i
float high_ = low_ + step
box box_id = vp.get(i)
for j = 0 to period -1
float source = src[j]
int value = int(volume_[j])
if source >= low_ - step and source <= high_ + step
volume_1.set(i, volume_1.get(i) + value)
volume_2.set(i, volume_2.get(i) + volume[j])
bg_col := volume_1.get(i) > 0 ?
color.from_gradient(volume_1.get(i), 0, volume_1.max(), color.new(up_col, 90), up_col)
: color.from_gradient(volume_1.get(i), volume_1.min(), 0, dn_col, color.new(dn_col, 90))
if na(box_id)
vp.set(i, box.new(n, high_, n+volume_1.get(i), low_, border_color = chart.bg_color, bgcolor = bg_col, force_overlay = true))
box_id.set_rightbottom(n+volume_1.get(i), low_)
box_id.set_lefttop(n, high_)
box_id.set_bgcolor(bg_col)
// Pocs
if volume_1.get(i) == volume_1.max() and (poc_type == 1 or poc_type == 3)
box.delete(pos_poc)
pos_poc := box.new(bar_index-period, high_, n, low_, text_size = size.normal, force_overlay = true)
pos_poc.set_bgcolor(color.new(bg_col, 90))
pos_poc.set_border_color(color.new(bg_col, 50))
pos_poc.set_text("+VWAP: "+str.tostring(volume_2.get(i), format.volume))
pos_poc.set_text_color(bg_col)
pos_poc.set_text_halign(text.align_left)
box.delete(pos_poc[1])
if volume_1.get(i) == volume_1.min() and (poc_type == 2 or poc_type == 3)
box.delete(neg_poc)
neg_poc := box.new(bar_index-period, high_, n, low_, text_size = size.normal, force_overlay = true)
neg_poc.set_bgcolor(color.new(bg_col, 90))
neg_poc.set_border_color(color.new(bg_col, 50))
neg_poc.set_text("-VWAP: "+str.tostring(volume_2.get(i), format.volume))
neg_poc.set_text_color(bg_col)
neg_poc.set_text_halign(text.align_left)
box.delete(neg_poc[1])
// Bg Box
box.delete(
box.new(bar_index - period, H, n, L
, border_color = na
, bgcolor = bgcol
, force_overlay = false
)[1]
)
// }
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
vwap_profile(src, period, bins)
vwap_col := last_bar_index - bar_index < period ? vwap_col : na
plot(last_bar_index - bar_index < period ? vwap : na, "VWAP", color = vwap_col, linewidth = 3, force_overlay = true)
plotcandle(open, high, low, close, title='Candles Color', color = vwap_col, wickcolor=vwap_col, bordercolor = vwap_col, force_overlay = true)
barcolor(vwap_col, display = display.none)
// }