我怎样才能像现在这样保持两天不加入的行数?
How can I keep lines my levels of two days not joined like it is now?
我正在使用我自己的代码绘制密谋级别。但是这两天的线是连在一起的,看起来很奇怪。我还想在每行的开头显示标签文本。现在它位于第一个栏的顶部。我该如何解决这个问题?
//@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 = round(previous_day_close + (previous_day_range) * 1.1 / 2, 2)
r3 = round(previous_day_close + (previous_day_range) * 1.1 / 4, 2)
r2 = round(previous_day_close + (previous_day_range) * 1.1 / 6, 2)
r1 = round(previous_day_close + (previous_day_range) * 1.1 / 12, 2)
r5 = round(r4 + 1.168 * (r4 - r3), 2)
r6 = round((previous_day_high / previous_day_low) * previous_day_close, 2)
// Supports
s4 = round(previous_day_close - (previous_day_range) * 1.1 / 2, 2)
s3 = round(previous_day_close - (previous_day_range) * 1.1 / 4, 2)
s2 = round(previous_day_close - (previous_day_range) * 1.1 / 6, 2)
s1 = round(previous_day_close - (previous_day_range) * 1.1 / 12, 2)
s5 = round(s4 - 1.168 * (s3 - s4), 2)
s6 = round(previous_day_close - (r6 - previous_day_close), 2)
// Plots
plot(r3 , title="H3: Go Short", style=plot.style_stepline, color=color.red, linewidth=2)
plot(r4 , title="H4: Long Breakout", style=plot.style_stepline, color=color.green, linewidth=2)
plot(r5 , title="H5: Target 1", style=plot.style_stepline, color=color.green, linewidth=2)
plot(r6 , title="H6: Target 2", style=plot.style_stepline, color=color.green, linewidth=2)
plot(s3 , title="L3: Go Long", style=plot.style_stepline, color=color.green, linewidth=2)
plot(s4 , title="L4: Short Breakout", style=plot.style_stepline, color=color.red, linewidth=2)
plot(s5 , title="L5: Target 1", style=plot.style_stepline, color=color.red, linewidth=2)
plot(s6 , title="L6: Target 2", style=plot.style_stepline, color=color.red, linewidth=2)
// Labels
if (change(r3))
label.new(bar_index, r3, text="H3: " + tostring(r3), style=label.style_none, textalign=text.align_left, yloc=yloc.abovebar)
if (change(r4))
label.new(bar_index, r4, text="H4: " + tostring(r4), style=label.style_none)
if (change(r5))
label.new(bar_index, r5, text="H5: " + tostring(r5), style=label.style_none)
if (change(r6))
label.new(bar_index, r6, text="H6: " + tostring(r6), style=label.style_none)
现在看起来像:
但我希望它看起来像此示例代码屏幕截图那样 https://www.tradingview.com/pine-script-docs/en/v4/essential/Drawings.html#pivot-points-standard。我需要更改哪些内容?
我正在尝试选项 textalign=text.align_left, yloc=yloc.abovebar
,但它们不是我这里问题的解决方案。我暂时保留了它们,这就是您在我的代码中看到它的原因。
连接的线可以这样固定。
//@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 = round(previous_day_close + (previous_day_range) * 1.1 / 2, 2)
r3 = round(previous_day_close + (previous_day_range) * 1.1 / 4, 2)
r2 = round(previous_day_close + (previous_day_range) * 1.1 / 6, 2)
r1 = round(previous_day_close + (previous_day_range) * 1.1 / 12, 2)
r5 = round(r4 + 1.168 * (r4 - r3), 2)
r6 = round((previous_day_high / previous_day_low) * previous_day_close, 2)
// Supports
s4 = round(previous_day_close - (previous_day_range) * 1.1 / 2, 2)
s3 = round(previous_day_close - (previous_day_range) * 1.1 / 4, 2)
s2 = round(previous_day_close - (previous_day_range) * 1.1 / 6, 2)
s1 = round(previous_day_close - (previous_day_range) * 1.1 / 12, 2)
s5 = round(s4 - 1.168 * (s3 - s4), 2)
s6 = round(previous_day_close - (r6 - previous_day_close), 2)
// Plots
plot(r3 , title="H3: Go Short", style=plot.style_linebr, color=change(r3)?na:color.red, linewidth=2)
plot(r4 , title="H4: Long Breakout", style=plot.style_linebr, color=change(r4)?na:color.green, linewidth=2)
plot(r5 , title="H5: Target 1", style=plot.style_linebr, color=change(r5)?na:color.green, linewidth=2)
plot(r6 , title="H6: Target 2", style=plot.style_linebr, color=change(r6)?na:color.green, linewidth=2)
plot(s3 , title="L3: Go Long", style=plot.style_linebr, color=change(s3)?na:color.green, linewidth=2)
plot(s4 , title="L4: Short Breakout", style=plot.style_linebr, color=change(s4)?na:color.red, linewidth=2)
plot(s5 , title="L5: Target 1", style=plot.style_linebr, color=change(s5)?na:color.red, linewidth=2)
plot(s6 , title="L6: Target 2", style=plot.style_linebr, color=change(s6)?na:color.red, linewidth=2)
// Labels
if (change(r3))
label.new(bar_index, r3, text="H3: " + tostring(r3), style=label.style_none, textalign=text.align_left, yloc=yloc.abovebar)
if (change(r4))
label.new(bar_index, r4, text="H4: " + tostring(r4), style=label.style_none)
if (change(r5))
label.new(bar_index, r5, text="H5: " + tostring(r5), style=label.style_none)
if (change(r6))
label.new(bar_index, r6, text="H6: " + tostring(r6), style=label.style_none)
产生
不确定你的意思
Also the label text I want to be present at the beginning of each line.
Right now it is on top of the first bar.
编辑 1 以响应
?:
是 ternary conditional operator。
这是 if-then-else
语法的简写形式。
此声明
color=change(s3)?na:color.green
等同于
if change(s3)
color := na
else
color := color.green
它的作用是在值更改时将线条的颜色设置为na
(=无颜色)。
通常,当绘图线更改值时,Pine 会绘制一条从旧值到新值的连接线,颜色与线相同,如本例中黄色所示:
那条 'connecting' 黄线的代码是
plot(s6 , title="L6: Target 2", style=plot.style_linebr, color=color.yellow)
因此,通过在值更改时将颜色设置为 na
(=无颜色),连接线变得不可见,其他(非黄色)线也可以看到。
当我们将 na
替换为另一种颜色时,连接线将显示为该颜色而不是不可见。
例如,如果我们将 s4
的代码更改为显示颜色 white
而不是 na
:
plot(s4 , title="L4: Short Breakout", style=plot.style_linebr, color=change(s4)?color.white:color.red, linewidth=2)
这将使连接线 white
而不是不可见。
我正在使用我自己的代码绘制密谋级别。但是这两天的线是连在一起的,看起来很奇怪。我还想在每行的开头显示标签文本。现在它位于第一个栏的顶部。我该如何解决这个问题?
//@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 = round(previous_day_close + (previous_day_range) * 1.1 / 2, 2)
r3 = round(previous_day_close + (previous_day_range) * 1.1 / 4, 2)
r2 = round(previous_day_close + (previous_day_range) * 1.1 / 6, 2)
r1 = round(previous_day_close + (previous_day_range) * 1.1 / 12, 2)
r5 = round(r4 + 1.168 * (r4 - r3), 2)
r6 = round((previous_day_high / previous_day_low) * previous_day_close, 2)
// Supports
s4 = round(previous_day_close - (previous_day_range) * 1.1 / 2, 2)
s3 = round(previous_day_close - (previous_day_range) * 1.1 / 4, 2)
s2 = round(previous_day_close - (previous_day_range) * 1.1 / 6, 2)
s1 = round(previous_day_close - (previous_day_range) * 1.1 / 12, 2)
s5 = round(s4 - 1.168 * (s3 - s4), 2)
s6 = round(previous_day_close - (r6 - previous_day_close), 2)
// Plots
plot(r3 , title="H3: Go Short", style=plot.style_stepline, color=color.red, linewidth=2)
plot(r4 , title="H4: Long Breakout", style=plot.style_stepline, color=color.green, linewidth=2)
plot(r5 , title="H5: Target 1", style=plot.style_stepline, color=color.green, linewidth=2)
plot(r6 , title="H6: Target 2", style=plot.style_stepline, color=color.green, linewidth=2)
plot(s3 , title="L3: Go Long", style=plot.style_stepline, color=color.green, linewidth=2)
plot(s4 , title="L4: Short Breakout", style=plot.style_stepline, color=color.red, linewidth=2)
plot(s5 , title="L5: Target 1", style=plot.style_stepline, color=color.red, linewidth=2)
plot(s6 , title="L6: Target 2", style=plot.style_stepline, color=color.red, linewidth=2)
// Labels
if (change(r3))
label.new(bar_index, r3, text="H3: " + tostring(r3), style=label.style_none, textalign=text.align_left, yloc=yloc.abovebar)
if (change(r4))
label.new(bar_index, r4, text="H4: " + tostring(r4), style=label.style_none)
if (change(r5))
label.new(bar_index, r5, text="H5: " + tostring(r5), style=label.style_none)
if (change(r6))
label.new(bar_index, r6, text="H6: " + tostring(r6), style=label.style_none)
现在看起来像:
但我希望它看起来像此示例代码屏幕截图那样 https://www.tradingview.com/pine-script-docs/en/v4/essential/Drawings.html#pivot-points-standard。我需要更改哪些内容?
我正在尝试选项 textalign=text.align_left, yloc=yloc.abovebar
,但它们不是我这里问题的解决方案。我暂时保留了它们,这就是您在我的代码中看到它的原因。
连接的线可以这样固定。
//@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 = round(previous_day_close + (previous_day_range) * 1.1 / 2, 2)
r3 = round(previous_day_close + (previous_day_range) * 1.1 / 4, 2)
r2 = round(previous_day_close + (previous_day_range) * 1.1 / 6, 2)
r1 = round(previous_day_close + (previous_day_range) * 1.1 / 12, 2)
r5 = round(r4 + 1.168 * (r4 - r3), 2)
r6 = round((previous_day_high / previous_day_low) * previous_day_close, 2)
// Supports
s4 = round(previous_day_close - (previous_day_range) * 1.1 / 2, 2)
s3 = round(previous_day_close - (previous_day_range) * 1.1 / 4, 2)
s2 = round(previous_day_close - (previous_day_range) * 1.1 / 6, 2)
s1 = round(previous_day_close - (previous_day_range) * 1.1 / 12, 2)
s5 = round(s4 - 1.168 * (s3 - s4), 2)
s6 = round(previous_day_close - (r6 - previous_day_close), 2)
// Plots
plot(r3 , title="H3: Go Short", style=plot.style_linebr, color=change(r3)?na:color.red, linewidth=2)
plot(r4 , title="H4: Long Breakout", style=plot.style_linebr, color=change(r4)?na:color.green, linewidth=2)
plot(r5 , title="H5: Target 1", style=plot.style_linebr, color=change(r5)?na:color.green, linewidth=2)
plot(r6 , title="H6: Target 2", style=plot.style_linebr, color=change(r6)?na:color.green, linewidth=2)
plot(s3 , title="L3: Go Long", style=plot.style_linebr, color=change(s3)?na:color.green, linewidth=2)
plot(s4 , title="L4: Short Breakout", style=plot.style_linebr, color=change(s4)?na:color.red, linewidth=2)
plot(s5 , title="L5: Target 1", style=plot.style_linebr, color=change(s5)?na:color.red, linewidth=2)
plot(s6 , title="L6: Target 2", style=plot.style_linebr, color=change(s6)?na:color.red, linewidth=2)
// Labels
if (change(r3))
label.new(bar_index, r3, text="H3: " + tostring(r3), style=label.style_none, textalign=text.align_left, yloc=yloc.abovebar)
if (change(r4))
label.new(bar_index, r4, text="H4: " + tostring(r4), style=label.style_none)
if (change(r5))
label.new(bar_index, r5, text="H5: " + tostring(r5), style=label.style_none)
if (change(r6))
label.new(bar_index, r6, text="H6: " + tostring(r6), style=label.style_none)
产生
不确定你的意思
Also the label text I want to be present at the beginning of each line.
Right now it is on top of the first bar.
编辑 1 以响应
?:
是 ternary conditional operator。
这是 if-then-else
语法的简写形式。
此声明
color=change(s3)?na:color.green
等同于
if change(s3)
color := na
else
color := color.green
它的作用是在值更改时将线条的颜色设置为na
(=无颜色)。
通常,当绘图线更改值时,Pine 会绘制一条从旧值到新值的连接线,颜色与线相同,如本例中黄色所示:
那条 'connecting' 黄线的代码是
plot(s6 , title="L6: Target 2", style=plot.style_linebr, color=color.yellow)
因此,通过在值更改时将颜色设置为 na
(=无颜色),连接线变得不可见,其他(非黄色)线也可以看到。
当我们将 na
替换为另一种颜色时,连接线将显示为该颜色而不是不可见。
例如,如果我们将 s4
的代码更改为显示颜色 white
而不是 na
:
plot(s4 , title="L4: Short Breakout", style=plot.style_linebr, color=change(s4)?color.white:color.red, linewidth=2)
这将使连接线 white
而不是不可见。