VWAP Price Channel

SamRecio · study · 69 行 · 点赞 3,902 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SamRecio
 
//@version=6
indicator("VWAP Price Channel", "VPC", overlay = true)
 
///_____________________________________________________________________________________________________________________
///Inputs
///‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
 
tf = input.timeframe("", title = "Timeframe")
len = input.int(20, title = "Length", minval = 1)
 
///_____________________________________________________________________________________________________________________
///VWAP Price Channel Function
///‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
 
get_vpc(_len) =>
    
//Main Logic
    hst = ta.highest(_len)
    lst = ta.lowest(_len)
 
    var float h_vwap = high
    var float l_vwap = low
 
    new_high = high == hst
    new_low = low == lst
 
    h_vwap := ta.vwap(high,new_high)
    l_vwap := ta.vwap(low,new_low)
 
    float upper = na
    float lower = na
 
    h_change = ta.change(h_vwap)
    l_change = ta.change(l_vwap)
 
    upper := new_high ? hst : (hst == hst[1] ? upper[1] + h_change : math.min(hst,upper[1] + h_change))
    lower := new_low ? lst : (lst == lst[1] ? lower[1] + l_change : math.max(lst,lower[1] + l_change))
 
    _avg = math.avg(upper,lower)
    
//Trend Detection & Coloring
    var int dir = 0
    var int dir2 = 0
    
    dir := new_high?1:new_low?-1:0
    dir2 := new_high?1:new_low?-1:dir2[1]
    
    [upper,lower,_avg,hst,lst,dir,dir2]
 
//Calling Function
[upper,lower,mid,hst,lst,dir,dir2] = request.security("",tf,get_vpc(len))
 
///_____________________________________________________________________________________________________________________
///Display
///‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
 
u = plot(upper, title = "Upper", color = dir == 1 ? color.rgb(0,0,0,100):color.rgb(255, 50, 50), style = plot.style_linebr)
l = plot(lower, title = "Lower", color = dir == -1 ? color.rgb(0,0,0,100):color.rgb(50, 255, 50), style = plot.style_linebr)
c = plot(close, display = display.none, editable = false)
 
fill(u,c,dir2 == 1?color.rgb(0,0,0,100):color.rgb(255, 50, 50, 95), title = "Fill")
fill(l,c,dir2 == -1?color.rgb(0,0,0,100):color.rgb(50, 255, 50, 95), title = "Fill")
 
plot(hst, title = "DC Upper", display = display.none)
plot(lst, title = "DC Lower", display = display.none)
//<---nice

← 返回列表