Pine script 扩展绘图函数

Pine script 扩展绘图函数,pine-script,Pine Script,下午好, 我目前正在使用下面的绘制一条线(使用昨天的数据),在今天的图表上绘制(当前仅绘制24小时)。 我想做的是让它一直延伸到右边 这可能吗 plot(pastLine, "Past Line", change(pastLine) ? na : color.purple, offset = 0) @比约恩:谢谢你的回复 延伸确实是错误的,这是我追求的轨道价格,但之前绘制的线 谢谢你抽出时间 丹尼尔 ##更新日期:2021年1月31日,1800-根据比约恩要求## 请参阅

下午好,

我目前正在使用下面的绘制一条线(使用昨天的数据),在今天的图表上绘制(当前仅绘制24小时)。 我想做的是让它一直延伸到右边

这可能吗

plot(pastLine, "Past Line", change(pastLine) ? na : color.purple, offset = 0)

@比约恩:谢谢你的回复 延伸确实是错误的,这是我追求的轨道价格,但之前绘制的线

谢谢你抽出时间 丹尼尔

##更新日期:2021年1月31日,1800-根据比约恩要求##

请参阅下面我使用的脚本。我想把之前所有的紫色线条延伸到价格轨道上

    //@version=4
study(title="Points of Interest", shorttitle="Points of Interest", overlay=true)

//Session Rules
bartimeSess = time('D')
newbarSess = bartimeSess != bartimeSess[1]
offset_val = input(title="Label Offset", type=input.integer, defval=6)

va_percent = input(0.7, title = "Value Area", type = input.float, 
     minval = 0.1, maxval = 1, step = 0.1)
     

dtf = input("D", title = "Time Frame", type = input.resolution)
resolution = input(1, title = "Resolution", type = input.float)

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

// }

// { VA

va_high_index = poc_index
va_low_index  = poc_index
    
va_vol_cap = sum_vol * va_percent
sum_va_vol = array.get(a, poc_index)

for i = 1 to a_size - 1
    
    above = 0.0
    if va_high_index + 1 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 1)), 0.0)
    if va_high_index + 2 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 2)), 0.0)
        
    below = 0.0
    if va_low_index - 1 > 0
        below := below + nz(array.get(a, (va_low_index - 1)), 0.0)
    if va_low_index - 2 > 0
        below := below + nz(array.get(a, (va_low_index - 2)), 0.0)
    
    if above > below
        va_high_index := min(va_high_index + 2, a_size - 1)
        sum_va_vol  := sum_va_vol + above
    else
        va_low_index := max(va_low_index - 2, 0)
        sum_va_vol := sum_va_vol + below
        
    if sum_va_vol >= va_vol_cap or (va_low_index <= 0 and va_high_index >= a_size - 1)
        break

// }

float p_poc = 0.0

float d_poc = 0.0
float b_poc = 0.0


d_poc  := poc_index * tick_size + a_min

if is_new_bar(dtf)
    p_poc  := d_poc[1]

else
    p_poc  := p_poc[1]


plot(p_poc, " pd_POC", change(p_poc) ? na : color.purple, offset = 0, trackprice=true)

plotshape(p_poc, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text="pdPOC",  offset = offset_val, transp=20, title="pdPOC")
/@version=4
研究(title=“兴趣点”,shorttitle=“兴趣点”,叠加=真)
//会话规则
bartimeSess=时间('D')
纽巴塞斯=巴蒂梅塞斯!=巴蒂梅塞斯[1]
偏移量=输入(title=“Label offset”,type=input.integer,deffal=6)
va_百分比=输入(0.7,title=“值区域”,type=input.float,
最小值=0.1,最大值=1,步长=0.1)
dtf=输入(“D”,title=“时间范围”,type=input.resolution)
分辨率=输入(1,title=“分辨率”,type=input.float)
是新的吗
更改(时间(t))!=0
四舍五入到最近的(v,x)=>
圆形(v/x)*x
勾号大小=最大值(syminfo.mintick,分辨率)
var a=数组。新浮点(0)
a_min=0.0,a_min:=nz(a_min[1],四舍五入到最近的(低,勾选大小))
a_max=0.0,a_max:=nz(a_max[1],四舍五入到最接近的(高,刻度大小))
d_开关=是新的_条(dtf)
如果d_开关
a_min:=低
a_max:=高
数组。清除(a)
//缩放最小最大值
v_min=int(四舍五入到最近的(低-a_min,勾号大小)/勾号大小)
v_max=int(四舍五入到最近的(高-最小值,勾号大小)/勾号大小)
//刻度烛光范围
刻度=v_最大值-v_最小值
音量=音量/(滴答声==0?1:滴答声)
对于i=v_最小值到最大值(v_最大值-1,v_最小值)
//插入新的低值
如果i<0
数组.插入(a,i-v_min,vol)
持续
//调整指数
偏移量=v_min<0?绝对值(v_min):0
索引=int(i+偏移量)
//推高价值
如果索引>=数组大小(a)
数组.推送(a,vol)
持续
//更新现有值
v=array.get(a,索引)
数组.set(a,索引,v+vol)
//数组边界
a_min:=min(a_min,四舍五入到最近的(低,勾号大小))
a_max:=max(a_max,四舍五入到最近的(高,勾号大小))
a_size=array.size(a)
//{POC
poc_指数=-1
poc_prev=-1.0
总体积=0.0
对于i=0到a_大小-1
poc_current=array.get(a,i)
总和体积:=总和体积+poc体积电流
如果poc_current>poc_prev
poc_prev:=poc_当前
poc_指数:=i
// }
//{VA
va_高_指数=poc_指数
va_低_指数=poc_指数
va_vol_cap=总量*va_百分比
sum_va_vol=array.get(a,poc_索引)
对于i=1到a_尺寸-1
高于=0.0
如果va_高指数+10
低于:=低于+nz(array.get(a,(va_low_index-1)),0.0)
如果va_低_指数-2>0
低于:=低于+nz(array.get(a,(va_low_index-2)),0.0)
如果高于>低于
va_high_index:=min(va_high_index+2,a_大小-1)
sum_va_vol:=sum_va_vol+以上
其他的
va_低_指数:=最大值(va_低_指数-2,0)
sum_va_vol:=下方的sum_va_vol+
如果总和=va\u vol>=va\u vol\u cap或(va\u low\u index=a\u size-1)
打破
// }
浮动p_poc=0.0
浮点数d_poc=0.0
浮动b_poc=0.0
d_poc:=poc_索引*勾号大小+最小值
如果是新条(dtf)
p_poc:=d_poc[1]
其他的
p_poc:=p_poc[1]
绘图(p_poc,“pd_poc”,更改(p_poc)?na:color.purple,偏移量=0,trackprice=true)
plotshape(p_poc,style=shape.labeldown,location=location.absolute,color=color.purple,textcolor=color.white,show_last=1,text=“pdPOC”,offset=offset_val,transp=20,title=“pdPOC”)

不能扩展
绘图。为此,您可以尝试使用
trackprice
参数

plot(pastLine, "Past Line", change(pastLine) ? na : color.purple, offset = 0, trackprice=true)
更新日期:2021年1月31日:使用直线代替绘图

//@version=4
study(title="Points of Interest", shorttitle="Points of Interest", overlay=true, max_lines_count=500)

//Session Rules
bartimeSess = time('D')
newbarSess = bartimeSess != bartimeSess[1]
offset_val = input(title="Label Offset", type=input.integer, defval=6)

va_percent = input(0.7, title = "Value Area", type = input.float, 
     minval = 0.1, maxval = 1, step = 0.1)
     

dtf = input("D", title = "Time Frame", type = input.resolution)
resolution = input(1, title = "Resolution", type = input.float)

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

// }

// { VA

va_high_index = poc_index
va_low_index  = poc_index
    
va_vol_cap = sum_vol * va_percent
sum_va_vol = array.get(a, poc_index)

for i = 1 to a_size - 1
    
    above = 0.0
    if va_high_index + 1 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 1)), 0.0)
    if va_high_index + 2 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 2)), 0.0)
        
    below = 0.0
    if va_low_index - 1 > 0
        below := below + nz(array.get(a, (va_low_index - 1)), 0.0)
    if va_low_index - 2 > 0
        below := below + nz(array.get(a, (va_low_index - 2)), 0.0)
    
    if above > below
        va_high_index := min(va_high_index + 2, a_size - 1)
        sum_va_vol  := sum_va_vol + above
    else
        va_low_index := max(va_low_index - 2, 0)
        sum_va_vol := sum_va_vol + below
        
    if sum_va_vol >= va_vol_cap or (va_low_index <= 0 and va_high_index >= a_size - 1)
        break

// }

float p_poc = 0.0
float d_poc = 0.0
float b_poc = 0.0

d_poc  := poc_index * tick_size + a_min

// if is_new_bar(dtf)
//     p_poc  := d_poc[1]
// else
//     p_poc  := p_poc[1]

p_poc := is_new_bar(dtf) ? d_poc[1] : p_poc[1]

if is_new_bar(dtf)
    line.new(time, p_poc, time+1, p_poc, xloc=xloc.bar_time, color=color.purple, extend=extend.right)

// plot(p_poc, " pd_POC", change(p_poc) ? na : color.purple, offset = 0, trackprice=true)

plotshape(p_poc, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text="pdPOC",  offset = offset_val, transp=20, title="pdPOC")
/@version=4
研究(title=“兴趣点”,shorttitle=“兴趣点”,叠加=true,最大线数=500)
//会话规则
bartimeSess=时间('D')
纽巴塞斯=巴蒂梅塞斯!=巴蒂梅塞斯[1]
偏移量=输入(title=“Label offset”,type=input.integer,deffal=6)
va_百分比=输入(0.7,title=“值区域”,type=input.float,
最小值=0.1,最大值=1,步长=0.1)
dtf=输入(“D”,title=“时间范围”,type=input.resolution)
分辨率=输入(1,title=“分辨率”,type=input.float)
是新的酒吧(t)=>改变(时间(t))!=0
四舍五入到最近的四舍五入(v,x)=>四舍五入(v/x)*x
勾号大小=最大值(syminfo.mintick,分辨率)
var a=数组。新浮点(0)
a_min=0.0,a_min:=nz(a_min[1],四舍五入到最近的(低,勾选大小))
a_max=0.0,a_max:=nz(a_max[1],四舍五入到最接近的(高,刻度大小))
d_开关=是新的_条(dtf)
如果d_开关
a_min:=低
a_max:=高
数组。清除(a)
//缩放最小最大值
v_min=int(四舍五入到最近的(低-a_min,勾号大小)/勾号大小)
v_max=int(四舍五入到最近的(高-最小值,勾号大小)/勾号大小)
//刻度烛光范围
刻度=v_最大值-v_最小值
音量=音量/(滴答声==0?1:滴答声)
对于i=v_最小值到最大值(v_最大值-1,v_最小值)
//插入新的低值
如果i<0
数组.插入(a,i-v_min,vol)
持续
//调整指数
偏移量=v_min<0?绝对值(v_min):0
索引=int(i+偏移量)
//推高价值
如果索引>=数组大小(a)
数组.推送(a,vol)
持续
//更新现有值
v=array.get(a,索引)
数组.set(a,索引,v+vol)
//数组边界
a_min:=min(a_min,四舍五入到最近的(低,勾号大小))
a_max:=max(a_max,四舍五入到最近的(高,勾号大小))
a_size=array.size(a)
//{POC
poc_指数=-1
poc_prev=-1.0
总体积=0.0
对于i=0到a_大小-1
poc_current=array.get(a,i)
总和体积:=总和体积
//@version=4
study(title="Points of Interest", shorttitle="Points of Interest", overlay=true, max_lines_count=500)

//Session Rules
bartimeSess = time('D')
newbarSess = bartimeSess != bartimeSess[1]
offset_val = input(title="Label Offset", type=input.integer, defval=6)

va_percent = input(0.7, title = "Value Area", type = input.float, 
     minval = 0.1, maxval = 1, step = 0.1)
     

dtf = input("D", title = "Time Frame", type = input.resolution)
resolution = input(1, title = "Resolution", type = input.float)

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

// }

// { VA

va_high_index = poc_index
va_low_index  = poc_index
    
va_vol_cap = sum_vol * va_percent
sum_va_vol = array.get(a, poc_index)

for i = 1 to a_size - 1
    
    above = 0.0
    if va_high_index + 1 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 1)), 0.0)
    if va_high_index + 2 < a_size - 1
        above := above + nz(array.get(a, (va_high_index + 2)), 0.0)
        
    below = 0.0
    if va_low_index - 1 > 0
        below := below + nz(array.get(a, (va_low_index - 1)), 0.0)
    if va_low_index - 2 > 0
        below := below + nz(array.get(a, (va_low_index - 2)), 0.0)
    
    if above > below
        va_high_index := min(va_high_index + 2, a_size - 1)
        sum_va_vol  := sum_va_vol + above
    else
        va_low_index := max(va_low_index - 2, 0)
        sum_va_vol := sum_va_vol + below
        
    if sum_va_vol >= va_vol_cap or (va_low_index <= 0 and va_high_index >= a_size - 1)
        break

// }

float p_poc = 0.0
float d_poc = 0.0
float b_poc = 0.0

d_poc  := poc_index * tick_size + a_min

// if is_new_bar(dtf)
//     p_poc  := d_poc[1]
// else
//     p_poc  := p_poc[1]

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=color.purple, 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))

// plot(p_poc, " pd_POC", change(p_poc) ? na : color.purple, offset = 0, trackprice=true)

plotshape(p_poc, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text="pdPOC",  offset = offset_val, transp=20, title="pdPOC")