本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Frien_dd
//@version=4
study("Chart Champions - Part 1 - nPOC - Levels - VWAPs", shorttitle="CC - Pt1 - Lvls nPOC VWAPs ", overlay=true)
//Monthly Open
mOpen = security(syminfo.tickerid, "M", open, lookahead = barmerge.lookahead_on)
pmOpen = security(syminfo.tickerid, "M", open[1], lookahead = barmerge.lookahead_on)
//Weekly Open
wOpen = security(syminfo.tickerid, "W", open, lookahead = barmerge.lookahead_on)
pwOpen = security(syminfo.tickerid, "W", open[1], lookahead = barmerge.lookahead_on)
//Previous Day Open High Low
dOpen = security(syminfo.tickerid, "D", open, lookahead=true)
pdOpen = security(syminfo.tickerid, "D", open[1], lookahead=true)
dbyOpen = security(syminfo.tickerid, "D", open[2], lookahead=true)
pdHigh = security(syminfo.tickerid, "D", high[1], lookahead=true)
pdLow = security(syminfo.tickerid, "D", low[1], lookahead=true)
pdEQ = (pdHigh + pdLow) / 2
pwHigh = security(syminfo.tickerid, "W", high[1], lookahead=true)
pwLow = security(syminfo.tickerid, "W", low[1], lookahead=true)
pwEQ = (pwHigh + pwLow) / 2
//Current Day High Low
dhigh = security(syminfo.tickerid, "D", high, lookahead=true)
dLow = security(syminfo.tickerid, "D", low, lookahead=true)
/// Input to show Lines and Labels for right of price in reference to the above
PriceDaily = input(true, title="Daily, EQ - (dOpen) - (pdHigh) - (pdLow) - (pdEQ)", group="Daily, Weekly, Monthly, EQ Price Axis")
PriceWeekly = input(true, title="Weekly, EQ - (pwEQ)", group="Daily, Weekly, Monthly, EQ Price Axis")
PriceMonthly = input(false, title="Monthly - (mOpen) - (pmOpen)", group="Daily, Weekly, Monthly, EQ Price Axis")
showdbyOpen = input(false, title="Show Day Before Yesterday Open (dbyOpen)", group="Optional Levels")
showpdOpen = input(false, title="Show Previous Day Open (pdOpen)", group="Optional Levels")
showwOpen = input(false, title="Show Weekly Open (wOpen)", group="Optional Levels")
showpwOpen = input(false, title="Show Previous Weekly Open (pwOpen)", group="Optional Levels")
// Line Var
var line mOpenLine = na
var line pmOpenLine = na
var line wOpenLine = na
var line pwOpenLine = na
var line pdOpenLine = na
var line dOpenLine = na
var line dbyOpenLine = na
var line pdHighLine = na
var line pdLowLine = na
var line pdEQLine = na
var line pwEQLine = na
//Label Var
var label mOpenLabel = na
var label pmOpenLabel = na
var label wOpenLabel = na
var label pwOpenLabel = na
var label dOpenLabel = na
var label pdOpenLabel = na
var label dbyOpenLabel = na
var label pdHighLabel = na
var label pdLowLabel = na
var label pdEQLabel = na
var label pwEQLabel = na
//Create Line
if PriceDaily
dOpenLine := line.new(bar_index[1], dOpen, bar_index, dOpen, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
pdHighLine := line.new(bar_index[1], pdHigh, bar_index, pdHigh, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
pdLowLine := line.new(bar_index[1], pdLow, bar_index, pdLow, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
pdEQLine := line.new(bar_index[1], pdEQ, bar_index, pdEQ, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
//Create Label
dOpenLabel := label.new(bar_index, dOpen, text = " dOpen - "+tostring(dOpen), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
pdHighLabel := label.new(bar_index, pdHigh, text = " pdHigh - "+tostring(pdHigh), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
pdLowLabel := label.new(bar_index, pdLow, text = " pdLow - "+tostring(pdLow), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
pdEQLabel := label.new(bar_index, pdEQ, text = " pdEQ - "+tostring(pdEQ), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
//Delete Line
line.delete(dOpenLine[1])
line.delete(pdHighLine[1])
line.delete(pdLowLine[1])
line.delete(pdEQLine[1])
//Delete Label
label.delete(dOpenLabel[1])
label.delete(pdHighLabel[1])
label.delete(pdLowLabel[1])
label.delete(pdEQLabel[1])
/////////////////////Weekly
if PriceWeekly
pwEQLine := line.new(bar_index[1], pwEQ, bar_index, pwEQ, color=color.yellow, style=line.style_dashed, width=1, extend=extend.right)
//Create Label
pwEQLabel := label.new(bar_index, pwEQ, text = " pwEQ - "+tostring(pwEQ), color=color.yellow, textcolor=color.yellow, style=label.style_none, size=size.normal, xloc=xloc.bar_index)
//Delete Line
line.delete(pwEQLine[1])
//Delete Label
label.delete(pwEQLabel[1])
////////////////////Monthly
if PriceMonthly
mOpenLine := line.new(bar_index[1], mOpen, bar_index, mOpen, color=color.purple, style=line.style_dashed, width=1, extend=extend.right)
pmOpenLine := line.new(bar_index[1], pmOpen, bar_index, pmOpen, color=color.purple, style=line.style_dashed, width=1, extend=extend.right)
//Create Label
mOpenLabel := label.new(bar_index, mOpen, text = " mOpen - "+tostring(mOpen), color=color.purple, textcolor=color.purple, style=label.style_none, size=size.normal, xloc=xloc.bar_index)
pmOpenLabel := label.new(bar_index, pmOpen, text = " pmOpen - "+tostring(pmOpen), color=color.purple, textcolor=color.purple, style=label.style_none, size=size.normal, xloc=xloc.bar_index)
//Delete Line
line.delete(mOpenLine[1])
line.delete(pmOpenLine[1])
//Delete Label
label.delete(mOpenLabel[1])
label.delete(pmOpenLabel[1])
/////////Optional Levels
if showdbyOpen
dbyOpenLine := line.new(bar_index[1], dbyOpen, bar_index, dbyOpen, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
dbyOpenLabel := label.new(bar_index, dbyOpen, text = " dbyOpen - "+tostring(dbyOpen), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(dbyOpenLine[1])
label.delete(dbyOpenLabel[1])
if showpdOpen
pdOpenLine := line.new(bar_index[1], pdOpen, bar_index, pdOpen, color=color.blue, style=line.style_dashed, width=1, extend=extend.right)
pdOpenLabel := label.new(bar_index, pdOpen, text = " pdOpen - "+tostring(pdOpen), color=color.blue, textcolor=color.blue, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pdOpenLine[1])
label.delete(pdOpenLabel[1])
if showwOpen
wOpenLine := line.new(bar_index[1], wOpen, bar_index, wOpen, color=color.yellow, style=line.style_dashed, width=1, extend=extend.right)
wOpenLabel := label.new(bar_index, wOpen, text = " wOpen - "+tostring(wOpen), color=color.yellow, textcolor=color.yellow, style=label.style_none, size=size.normal, xloc=xloc.bar_index)
line.delete(wOpenLine[1])
label.delete(wOpenLabel[1])
if showpwOpen
pwOpenLine := line.new(bar_index[1], pwOpen, bar_index, pwOpen, color=color.yellow, style=line.style_dashed, width=1, extend=extend.right)
pwOpenLabel := label.new(bar_index, pwOpen, text = " pwOpen - "+tostring(pwOpen), color=color.yellow, textcolor=color.yellow, style=label.style_none, size=size.normal, xloc=xloc.bar_index)
line.delete(pwOpenLine[1])
label.delete(pwOpenLabel[1])
/////////////////////////////////VWAPs
show_DVWAPs = input(false, title = "Daily", group = "Optional VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
show_WVWAPs = input(false, title = "Weekly", group = "Optional VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
show_MVWAPs = input(false, title = "Monthly", group = "Optional VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
show_DVWAPs_color = show_DVWAPs ? color.blue : na
show_DVWAPs_text = show_DVWAPs ? color.white : na
show_WVWAPs_color = show_WVWAPs ? color.yellow : na
show_WVWAPs_text = show_WVWAPs ? color.black : na
show_MVWAPs_color = show_MVWAPs ? color.purple : na
show_MVWAPs_text = show_MVWAPs ? color.white : na
is_today = year == year(timenow) and month == month(timenow) and dayofmonth == dayofmonth(timenow)
//Daily VWAP
VWAP = round(vwap)
plot(VWAP, "D-VWAP", is_today ? show_DVWAPs_color : na, offset = 0)
var label VWAPLabel = na
VWAPLabel := label.new(timenow, VWAP, xloc = xloc.bar_time, text = "D-VWAP - "+tostring(VWAP), color = show_DVWAPs_color, textcolor = show_DVWAPs_text, style = label.style_label_left, size=size.small)
label.delete(VWAPLabel[1])
//Previous Day's Closing Vwap
newday(res) =>
t = time(res)
change(t) != 0 ? 1 : 0
new_day = newday("D")
pdVWAP = valuewhen(new_day, int(VWAP[1]), 0)
plot(pdVWAP, "pdVWAP", is_today ? show_DVWAPs_color : na, offset = 0)
var label pdVWAPLabel = na
pdVWAPLabel := label.new(timenow, pdVWAP, xloc = xloc.bar_time, text = "pdVWAP - "+tostring(pdVWAP), color = show_DVWAPs_color, textcolor = show_DVWAPs_text, style = label.style_label_left, size=size.small)
label.delete(pdVWAPLabel[1])
//Weeekly VWAP
src = hlc3
wt = time("W")
wstart = na(wt[1]) or wt > wt[1]
wsumSrc = src * volume
wsumVol = volume
wsumSrc := wstart ? wsumSrc : wsumSrc + wsumSrc[1]
wsumVol := wstart ? wsumVol : wsumVol + wsumVol[1]
wvw=round(wsumSrc / wsumVol)
plot(timeframe.isintraday ? wvw : na, title="W-VWAP", color=show_WVWAPs_color)
var label wVWAPLabel = na
wVWAPLabel := label.new(timenow, timeframe.isintraday ? wvw : na, xloc = xloc.bar_time, text = "W-VWAP - "+tostring(timeframe.isintraday ? wvw : na), color = show_WVWAPs_color, textcolor = show_WVWAPs_text, style = label.style_label_left, size=size.small)
label.delete(wVWAPLabel[1])
//Monthly VWAP
mt = time("M")
mstart = na(mt[1]) or mt > mt[1]
msumSrc = src * volume
msumVol = volume
msumSrc := mstart ? msumSrc : msumSrc + msumSrc[1]
msumVol := mstart ? msumVol : msumVol + msumVol[1]
mvw=round(msumSrc / msumVol)
plot(timeframe.isintraday ? mvw : na, title="M-VWAP", color=show_MVWAPs_color)
var label mVWAPLabel = na
mVWAPLabel := label.new(timenow, timeframe.isintraday ? mvw : na, xloc = xloc.bar_time, text = "M-VWAP - "+tostring(timeframe.isintraday ? mvw : na), color = show_MVWAPs_color, textcolor = show_MVWAPs_text, style = label.style_label_left, size=size.small)
label.delete(mVWAPLabel[1])
//Session Rules
bartimeSess = time('D')
newbarSess = bartimeSess != bartimeSess[1]
show_nPOCs = input(true, title = "Show Naked POCs", group = "Naked Point of Control Settings", type = input.bool)
dtf = input("D", title = "nPOC - Time Frame", type = input.resolution, group="Naked Point of Control Settings")
resolution = input(1, title = "Symbol Resolution", type = input.float, group="Naked Point of Control Settings")
show_nPOCs_color = show_nPOCs ? #FFC0CB : na
is_new_bar(t) => change(time(t)) != 0
round_to_nearest(v, x) => round(v / x) * x
tick_size = max(syminfo.mintick, resolution)
var a = array.new_float(0)
a_min = 0.0, a_min := nz(a_min[1], round_to_nearest(low, tick_size))
a_max = 0.0, a_max := nz(a_max[1], round_to_nearest(high, tick_size))
d_switch = is_new_bar(dtf)
if d_switch
a_min := low
a_max := high
array.clear(a)
// Scaled min max
v_min = int(round_to_nearest(low - a_min, tick_size) / tick_size)
v_max = int(round_to_nearest(high - a_min, tick_size) / tick_size)
// Scaled candle range
ticks = v_max - v_min
vol = volume / (ticks == 0 ? 1 : ticks)
for i = v_min to max(v_max - 1, v_min)
// Insert new low value
if i < 0
array.insert(a, i - v_min, vol)
continue
// Adjust index
offset = v_min < 0 ? abs(v_min) : 0
index = int(i + offset)
// Push new high value
if index >= array.size(a)
array.push(a, vol)
continue
// Update existing value
v = array.get(a, index)
array.set(a, index, v + vol)
// Array bounds
a_min := min(a_min, round_to_nearest(low, tick_size))
a_max := max(a_max, round_to_nearest(high, tick_size))
a_size = array.size(a)
// POC
poc_index = -1
poc_prev = -1.0
sum_vol = 0.0
for i = 0 to a_size - 1
poc_current = array.get(a, i)
sum_vol := sum_vol + poc_current
if poc_current > poc_prev
poc_prev := poc_current
poc_index := i
float p_poc = 0.0
float d_poc = 0.0
float b_poc = 0.0
d_poc := poc_index * tick_size + a_min
p_poc := is_new_bar(dtf) ? d_poc[1] : p_poc[1]
var line[] lines = array.new_line()
var float[] pocs = array.new_float()
if is_new_bar(dtf)
array.push(lines, line.new(time, p_poc, time+1, p_poc, xloc=xloc.bar_time, color=show_nPOCs_color, extend=extend.right))
array.push(pocs, p_poc)
if array.size(pocs) > 0
for i = 0 to array.size(pocs)-1
mypoc = array.get(pocs,i)
if mypoc > low
line.delete(array.get(lines,i))