实现在蜡烛收盘之后删除线的方法

huangapple go评论47阅读模式
英文:

How to implement line removal after closing the candle above it

问题

Here is the translation of the text you provided:

"我请求帮助。
我编写了一个指标,但卡住了 - 找不到解决方案。

所以 - 历史上有一些信号,从中自动绘制水平线 - 创建了一个数组。
我根据需要调整显示的线条数量。

因此,显示的线条在其延续部分与蜡烛有交汇 - 即,蜡烛收盘价高于该线。

我需要蜡烛穿过的线条被移除,或者改变颜色...

而且,当出现新的信号时,会出现新的线条...

移除或更改颜色严格在蜡烛收盘价高于该线后发生...

我尝试了很多选项 - 但没有一个能正常工作...

我附上了一个我无法超越的代码...

谢谢..."

Please note that I've provided the translation without the code part, as you requested.

英文:

I ask for help.
I write an indicator, but I'm stuck - I can't find a solution.

And so - there is some signal in history, a horizontal line is automatically drawn from it - an array is created.
I adjust the number of displayed lines accordingly.

Accordingly, the displayed lines on their continuation have intersections with candles - that is, the candle closes above the line.

I need the lines that were crossed by the candles to be removed, well, or change color...

And accordingly, when a new signal appears, new lines appear...

Removal or color change occurs strictly after closing the candle above the line...

I tried a bunch of options - but not a single one works correctly...

I attach a code that I could not go beyond...

Thank you...

//@version=5
indicator("NHNHNHNH", overlay = true)
Kol_Linii = input(2, "Количество линий")

Signal = open[3] < close[3] and open[2] < close[2] and open[1] < close[1] and close < open and high[1] > high and high[1] > close[1] and high > open)

X_for_LINIA = ta.valuewhen(Signal, bar_index, 0)
Y_for_LINIA = ta.valuewhen(Signal, high, 0)

var b = array.new_float()
array.push(b, Y_for_LINIA)

peresechenie = ta.crossover(close, Y_for_LINIA)
var p = array.new_bool()
array.push(p, peresechenie)

if Signal
    LINIA = line.new(X_for_LINIA, Y_for_LINIA,X_for_LINIA+1,Y_for_LINIA, extend = extend.right, color = color.fuchsia, width = 1)
    var a = array.new_line()
    array.push(a, LINIA)
    
    var line_price = array.new_float()
    array.push(line_price, line.get_price(LINIA, bar_index))

     
    if array.size(a) > Kol_Linii
        ln = array.shift(a)
        line.delete(ln) `

实现在蜡烛收盘之后删除线的方法

答案1

得分: 0

你应该使用一个数组来存储你的线条。然后,在每次关闭时,循环遍历数组中的所有线条。如果线条的Y值小于当前的收盘价(蜡烛收盘价高于线条),则删除该线条和对应的数组行。

我测试过这段代码,它运行良好:

//@version=5
indicator("NHNHNHNH", overlay = true)
Kol_Linii = input(2, "Количество линий")

Signal = open[3] < close[3] and open[2] < close[2] and open[1] < close[1] and close < open and high[1] > high and high[1] > close[1] and high > open

X_for_LINIA = ta.valuewhen(Signal, bar_index, 0)
Y_for_LINIA = ta.valuewhen(Signal, high, 0)

var b = array.new_float()
array.push(b, Y_for_LINIA)

peresechenie = ta.crossover(close, Y_for_LINIA)
var p = array.new_bool()
array.push(p, peresechenie)

var ArrayLine = array.new_line()

if Signal
    LINIA = line.new(X_for_LINIA, Y_for_LINIA,X_for_LINIA+1,Y_for_LINIA, extend = extend.right, color = color.fuchsia, width = 1)
    array.push(ArrayLine, LINIA)
    label.new(bar_index, close, str.tostring(array.size(ArrayLine)) + " : " + str.tostring(line.get_y1(LINIA)), color= color.white, yloc=yloc.abovebar)

if array.size(ArrayLine) > 0
    NumberOfLine = array.size(ArrayLine) 
    Complete = false
    Index = NumberOfLine - 1
    while not(Complete)
        Line = array.get(ArrayLine, Index)
        if line.get_y1(Line) < close
            line.delete(Line)
            array.remove(ArrayLine, Index)
        Index := Index - 1
        if Index < 0
            Complete := true

为了测试目的,我添加了一个标签,显示了ArrayLine数组的大小和Y线的值,你可以删除它。

英文:

You should use an array to store your lines.
Then, on each close, loop over all the lines in this array.
If the Y value of the line is inferior to the actual close (= the candle close is above the line), delete the line and delete the corresponding array row.
I tested this code which works well :

//@version=5
indicator(&quot;NHNHNHNH&quot;, overlay = true)
Kol_Linii = input(2, &quot;Количество линий&quot;)

Signal = open[3] &lt; close[3] and open[2] &lt; close[2] and open[1] &lt; close[1] and close &lt; open and high[1] &gt; high and high[1] &gt; close[1] and high &gt; open

X_for_LINIA = ta.valuewhen(Signal, bar_index, 0)
Y_for_LINIA = ta.valuewhen(Signal, high, 0)

var b = array.new_float()
array.push(b, Y_for_LINIA)

peresechenie = ta.crossover(close, Y_for_LINIA)
var p = array.new_bool()
array.push(p, peresechenie)

var ArrayLine = array.new_line()

if Signal
    LINIA = line.new(X_for_LINIA, Y_for_LINIA,X_for_LINIA+1,Y_for_LINIA, extend = extend.right, color = color.fuchsia, width = 1)
    array.push(ArrayLine, LINIA)
    label.new(bar_index, close, str.tostring(array.size(ArrayLine))+&quot; : &quot; + str.tostring(line.get_y1(LINIA)), color= color.white, yloc=yloc.abovebar)
    
if array.size(ArrayLine) &gt; 0
    NumberOfLine = array.size(ArrayLine) 
    Complete = false
    Index = NumberOfLine - 1
    while not(Complete)
        Line = array.get(ArrayLine, Index)
        if line.get_y1(Line) &lt; close
            line.delete(Line)
            array.remove(ArrayLine, Index)
        Index := Index - 1
        if Index &lt; 0
            Complete := true

I put a label with the size of the ArrayLine array and the value of the Y line for testing purpose, you can delete it :
实现在蜡烛收盘之后删除线的方法

huangapple
  • 本文由 发表于 2023年4月17日 17:40:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定