为什么我的标签文本一直重复而不是每行一次

Why my label text kept on repeating instead of one time per line

我正在编写一个小脚本来在 tradingview 图表上绘制 camarilla 线。但我不确定为什么该行上方的标签文本会重复出现。谁能帮我解决一下?

我按照这个 example 看看如何绘制标签。

我的代码:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nooby_trader

//@version=4
study("Camarilla 1-6", overlay=true)

previous_day_close = security(syminfo.tickerid, "D", close[1] )
previous_day_high = security(syminfo.tickerid, "D", high[1])
previous_day_low = security(syminfo.tickerid, "D", low[1])

// Resistances 
r4 = previous_day_close + (previous_day_high- previous_day_low) * 1.1 / 2
r3 = previous_day_close + (previous_day_high- previous_day_low) * 1.1 / 4
r2 = previous_day_close + (previous_day_high- previous_day_low) * 1.1 / 6
r1 = previous_day_close + (previous_day_high- previous_day_low) * 1.1 / 12

r5 = r4 + 1.168 * (r4 - r3)
r6 = (previous_day_high / previous_day_low) * previous_day_close

label.new(bar_index, r3, text="H3", style=label.style_none)
plot(r3 , title="H3: Go Short", style=plot.style_line, color=color.red, linewidth=1)
label.new(bar_index, r4, text="H4", style=label.style_none)
plot(r4 , title="H4: Long Breakout", style=plot.style_line, color=color.green, linewidth=1)
label.new(bar_index, r5, text="H5", style=label.style_none)
plot(r5 , title="H5: Target 1", style=plot.style_line, color=color.green, linewidth=1)
label.new(bar_index, r6, text="H6", style=label.style_none)
plot(r6 , title="H6: Target 2", style=plot.style_line, color=color.green, linewidth=1)

// Supports 
s4 = previous_day_close - (previous_day_high - previous_day_low) * 1.1 / 2
s3 = previous_day_close - (previous_day_high - previous_day_low) * 1.1 / 4
s2 = previous_day_close - (previous_day_high - previous_day_low) * 1.1 / 6
s1 = previous_day_close - (previous_day_high - previous_day_low) * 1.1 / 12

s5 = s4 - 1.168 * (s3 - s4)
s6 = previous_day_close - (r6 - previous_day_close)

plot(s3 , title="L3: Go Long", style=plot.style_line, color=color.green, linewidth=1)
plot(s4 , title="L4: Short Breakout", style=plot.style_line, color=color.red, linewidth=1)
plot(s5 , title="L5: Target 1", style=plot.style_line, color=color.red, linewidth=1)
plot(s6 , title="L6: Target 2", style=plot.style_line, color=color.red, linewidth=1)

看起来像这样

那是因为您的代码试图在每个柱上设置标签。
Pine 垃圾收集器只保留图表上最近的 50 个绘图对象,并删除最旧的。有关详细信息,请参阅

这将绘制出您要查找的内容:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nooby_trader

//@version=4
study("Camarilla 1-6", overlay=true) 

[previous_day_high, previous_day_low, previous_day_close] = security(syminfo.tickerid, "D", [high[1], low[1], close[1]])

previous_day_range = previous_day_high - previous_day_low

// Resistances 
r4 = previous_day_close + (previous_day_range) * 1.1 / 2
r3 = previous_day_close + (previous_day_range) * 1.1 / 4
r2 = previous_day_close + (previous_day_range) * 1.1 / 6
r1 = previous_day_close + (previous_day_range) * 1.1 / 12

r5 = r4 + 1.168 * (r4 - r3)
r6 = (previous_day_high / previous_day_low) * previous_day_close

// Supports 
s4 = previous_day_close - (previous_day_range) * 1.1 / 2
s3 = previous_day_close - (previous_day_range) * 1.1 / 4
s2 = previous_day_close - (previous_day_range) * 1.1 / 6
s1 = previous_day_close - (previous_day_range) * 1.1 / 12

s5 = s4 - 1.168 * (s3 - s4)
s6 = previous_day_close - (r6 - previous_day_close) 

// Plots
plot(r3 , title="H3: Go Short",       style=plot.style_stepline, color=color.red,   linewidth=1)
plot(r4 , title="H4: Long Breakout",  style=plot.style_stepline, color=color.green, linewidth=1)
plot(r5 , title="H5: Target 1",       style=plot.style_stepline, color=color.green, linewidth=1)
plot(r6 , title="H6: Target 2",       style=plot.style_stepline, color=color.green, linewidth=1)

plot(s3 , title="L3: Go Long",        style=plot.style_stepline, color=color.green, linewidth=1)
plot(s4 , title="L4: Short Breakout", style=plot.style_stepline, color=color.red,   linewidth=1)
plot(s5 , title="L5: Target 1",       style=plot.style_stepline, color=color.red,   linewidth=1)
plot(s6 , title="L6: Target 2",       style=plot.style_stepline, color=color.red,   linewidth=1)

// Labels
if (change(r3))
    label.new(bar_index, r3, text="H3", style=label.style_none)

if (change(r4))
    label.new(bar_index, r4, text="H4", style=label.style_none)

if (change(r5))
    label.new(bar_index, r5, text="H5", style=label.style_none)

if (change(r6))
    label.new(bar_index, r6, text="H6", style=label.style_none)