扩展打印功能 [英] Extending plot function

查看:17
本文介绍了扩展打印功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午,

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

这可能吗?

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

@比约恩感谢您的回复 扩展确实是错误的,这是我想要的跟踪价格,但对于之前绘制的线条。

感谢您抽出时间 丹尼尔

##更新日期:2021/31@1800--根据Bjorn请求##

请参阅下面我使用的脚本。我想将前面的所有紫色线条扩展到价格跟踪。

    //@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")

推荐答案

不能扩展plot。您可以尝试使用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")

产生以下结果(最多500行)

编辑%1响应this comment
保持未中断的PoC

//@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")

这篇关于扩展打印功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆