本文介绍了当30分钟的蜡烛关闭时,创建一条线。每高50美元,低50美元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午,

有没有办法在每50美元一支30分钟的蜡烛结束后创建一条新的线。

那么当价格回传时,这些行将被删除且不会重新创建?

我正在尝试让它突出显示单个印花,其中24小时内的价格在30分钟蜡烛后没有回溯。

我认为这个问题中的不间断元素可能会起作用。Extending plot function

下面是一个示例

//@version=4
study("Single Print", shorttitle="SP", overlay=true)
//30 min chart
Incr = input(50, "Increment(50)")

Date = input(title="Date", type=input.time, defval=timestamp("27 Jun 2021 00:00"))


Top = 0.0, Bot = 0.0
Top := time == Date? high : Top[1]
Bot := time == Date? low  : Bot[1]

if time > Date
    Top := high > Top[1]? high : Top[1]
    Bot := low  < Bot[1]? low  : Bot[1]

rTop = ceil(Top/Incr) * Incr
rBot = floor(Bot/Incr) * Incr


NoLines = (rTop - rBot) / Incr
//array
a_lines = array.new_float(NoLines)
for x = 0 to NoLines -1
    array.set(a_lines, x, rBot + (x * Incr))

a_used = array.new_bool(NoLines)
for x = 0 to NoLines -1
    break
    //Determine if line was already used


Get_Array(ArrayName,index) => value = array.get(ArrayName,index)

for i = 0 to NoLines - 1
    Y = Get_Array(a_lines,i)
    U = Get_Array(a_used,i)
    theline = line.new(x1 = Date, y1 = Y, x2 = timenow, y2 = Y, 
      color=color.new(color.red, 70), width=3, extend=extend.none, xloc=xloc.bar_time)
    if U
        line.delete(theline)

#更新至问题28/06/2021#

比约恩一如既往地令人惊叹。

我还有第二个问题,我不确定它是否可以实现。

  1. 有没有办法使区间达到50美元的整数(可能四舍五入高位/低)。

  2. 创建行并删除通过该行传回的价格时,是否有办法在创建新的价格活动行时(在删除之后)回顾并表示,如果我们要删除行,请不要创建新行。

这将只留下尚未被价格走势回调的区域。这有意义吗?

推荐答案

可能是这样的?

//@version=4

var int     max_lines = 500

study("Lines", max_lines_count=max_lines, overlay=true)

i_line_distance = input(50,        "Distance between lines",            input.float)
i_max_array     = input(max_lines, "Max array size",                    input.integer, minval=max_lines, maxval=100000)
i_include_high  = input(true,      "Draw line at high",                 input.bool)
i_remove_gaps   = input(true,      "Remove line if price gaps over it", input.bool)

var line[]  a_lines     = array.new_line()
var float   last_level  = na
var int     size_array  = na

f_add_line(_level) =>
    if array.size(a_lines) >= i_max_array
        line.delete(array.shift(a_lines))
    array.push(a_lines, line.new(bar_index-1, _level, bar_index, _level, extend=extend.right))
    _level

// Create new lines
if barstate.isconfirmed[1]
    lo = low[1], hi = high[1]

    for level = lo to hi by i_line_distance
        last_level := f_add_line(level)

    if i_include_high and last_level != hi
        f_add_line(hi)

// Delete touched lines
a_idx_deleted = array.new_int()
size_array := array.size(a_lines)
if size_array > 0
    for i = 0 to size_array - 1
        p = line.get_price(array.get(a_lines, i), bar_index)
        if (p >= low and p <= high) or (i_remove_gaps and ((p >= high[1] and p <= high) or (p <= low[1] and p >= low)))
            line.delete(array.get(a_lines, i))
            array.push(a_idx_deleted, i) // Remember which line was deleted (for cleanup of lines array)

// Remove deleted lines from lines array
array.reverse(a_idx_deleted)
size_array := array.size(a_idx_deleted)
if size_array > 0
    for i = 0 to size_array - 1
        array.remove(a_lines, array.get(a_idx_deleted, i))

编辑%1响应this comment

//@version=4

var int     max_lines = 500

study("Lines", max_lines_count=max_lines, overlay=true)

i_line_distance = input(50,        "Distance between lines",            input.float)
i_max_array     = input(max_lines, "Max array size",                    input.integer, minval=max_lines, maxval=100000)
i_remove_gaps   = input(true,      "Remove line if price gaps over it", input.bool)

var line[]  a_lines             = array.new_line()
var float[] a_levels_deleted    = array.new_float()
var float   last_level          = na
var int     size_array          = na

f_add_line(_level) =>
    if not array.includes(a_levels_deleted, _level) // Don't redraw deleted lines
        if array.size(a_lines) >= i_max_array
            line.delete(array.shift(a_lines))
        array.push(a_lines, line.new(bar_index-1, _level, bar_index, _level, extend=extend.right))

// Create new lines
if barstate.isconfirmed[1]
    // Round to interval
    lo = ceil(low[1] / i_line_distance) * i_line_distance
    hi = floor(high[1] / i_line_distance) * i_line_distance

    for level = lo to hi by i_line_distance
        f_add_line(level)


// Delete touched lines
a_idx_deleted = array.new_int()
size_array := array.size(a_lines)
if size_array > 0
    for i = 0 to size_array - 1
        p = line.get_price(array.get(a_lines, i), bar_index)
        if (p >= low and p <= high) or (i_remove_gaps and ((p >= high[1] and p <= high) or (p <= low[1] and p >= low)))
            line.delete(array.get(a_lines, i))
            array.push(a_idx_deleted, i) // Remember which line was deleted (for cleanup of lines array)
            array.push(a_levels_deleted, p)

// Remove deleted lines from lines array
array.reverse(a_idx_deleted)
size_array := array.size(a_idx_deleted)
if size_array > 0
    for i = 0 to size_array - 1
        array.remove(a_lines, array.get(a_idx_deleted, i))

编辑%2响应this comment

//@version=4

var int     max_lines = 500

study("Lines", max_lines_count=max_lines, overlay=true)

i_line_distance = input(50,                         "Distance between lines",            input.float)
i_max_array     = input(max_lines,                  "Max array size",                    input.integer, minval=max_lines, maxval=100000)
i_remove_gaps   = input(true,                       "Remove line if price gaps over it", input.bool)

var line[]  a_lines             = array.new_line()
var float[] a_levels_deleted    = array.new_float()
var int     size_array          = na

f_add_line(_level) =>
    if not array.includes(a_levels_deleted, _level) // Don't redraw deleted lines
        if array.size(a_lines) >= i_max_array
            line.delete(array.shift(a_lines))
        array.push(a_lines, line.new(bar_index-1, _level, bar_index, _level, extend=extend.right))

// Only plot last 24h
if change(dayofweek)
    size_array := array.size(a_lines)
    if size_array > 0
        for i = 0 to size_array - 1
            line.delete(array.get(a_lines, i))
    array.clear(a_lines)
    array.clear(a_levels_deleted)

// Create new lines
if barstate.isconfirmed[1]
    // Round to interval
    lo = ceil(low[1] / i_line_distance) * i_line_distance
    hi = floor(high[1] / i_line_distance) * i_line_distance

    for level = lo to hi by i_line_distance
        f_add_line(level)


// Delete touched lines
a_idx_deleted = array.new_int()
size_array := array.size(a_lines)
if size_array > 0
    for i = 0 to size_array - 1
        p = line.get_price(array.get(a_lines, i), bar_index)
        if (p >= low and p <= high) or (i_remove_gaps and ((p >= high[1] and p <= high) or (p <= low[1] and p >= low)))
            line.delete(array.get(a_lines, i))
            array.push(a_idx_deleted, i) // Remember which line was deleted (for cleanup of lines array)
            array.push(a_levels_deleted, p)


// Remove deleted lines from lines array
array.reverse(a_idx_deleted)
size_array := array.size(a_idx_deleted)
if size_array > 0
    for i = 0 to size_array - 1
        array.remove(a_lines, array.get(a_idx_deleted, i))

编辑3保持每天的行数不变

//@version=4

var int     max_lines = 500

study("Lines", max_lines_count=max_lines, overlay=true)

i_line_distance = input(50,                         "Distance between lines",            input.float)
i_max_array     = input(max_lines,                  "Max array size",                    input.integer, minval=max_lines, maxval=100000)
i_remove_gaps   = input(true,                       "Remove line if price gaps over it", input.bool)

var line[]  a_lines             = array.new_line()
var float[] a_levels_deleted    = array.new_float()
var int     size_array          = na

f_add_line(_level) =>
    if not array.includes(a_levels_deleted, _level) // Don't redraw deleted lines
        if array.size(a_lines) >= i_max_array
            line.delete(array.shift(a_lines))
        array.push(a_lines, line.new(bar_index-1, _level, bar_index, _level, extend=extend.right))

// Keep untouched lines for each day
if change(dayofweek)
    // change length of existing lines
    size_array := array.size(a_lines)
    if size_array > 0
        for i = 0 to size_array - 1
            myLine = array.get(a_lines, i)
            line.set_x2(myLine, bar_index)
            line.set_extend(myLine, extend.none)
    array.clear(a_lines)
    array.clear(a_levels_deleted)

// Create new lines
if barstate.isconfirmed[1]
    // Round to interval
    lo = ceil(low[1] / i_line_distance) * i_line_distance
    hi = floor(high[1] / i_line_distance) * i_line_distance

    for level = lo to hi by i_line_distance
        f_add_line(level)


// Delete touched lines
a_idx_deleted = array.new_int()
size_array := array.size(a_lines)
if size_array > 0
    for i = 0 to size_array - 1
        p = line.get_price(array.get(a_lines, i), bar_index)
        if (p >= low and p <= high) or (i_remove_gaps and ((p >= high[1] and p <= high) or (p <= low[1] and p >= low)))
            line.delete(array.get(a_lines, i))
            array.push(a_idx_deleted, i) // Remember which line was deleted (for cleanup of lines array)
            array.push(a_levels_deleted, p)


// Remove deleted lines from lines array
array.reverse(a_idx_deleted)
size_array := array.size(a_idx_deleted)
if size_array > 0
    for i = 0 to size_array - 1
        array.remove(a_lines, array.get(a_idx_deleted, i))

这篇关于当30分钟的蜡烛关闭时,创建一条线。每高50美元,低50美元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:08