如何更改 Plot 的长度?
How to change the length of the Plot?
我有一个问题,我想要线图,在穿过蜡烛时停止并且没有在图表上向右移动,而那些没有与蜡烛交叉的线不断走向正确的。是否可以用 Plot 做到这一点?
lengthGroupTitle = "Настройка уровней"
leftLenH = input.int(title="Множитель уровня ликвидации, относительно ТФ", defval=100, minval=1, group=lengthGroupTitle)
rightLenH = leftLenH
leftLenL = leftLenH
rightLenL = leftLenL
ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
drawLabel(_offset, _pivot, _style, _color, _textColor) =>
if not na(_pivot)
label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)
atr1 = ta.atr(10)
atr2 = ta.atr(10)
atr3 = ta.atr(10)
atr4 = ta.atr(10)
perc_dist4 = int(0.3)
atr5 = ta.atr(10)
perc_dist5 = int(1.2)
atr6 = ta.atr(10)
perc_dist6 = int(3)
pos1 = close + close *0.49 /100
pos2 = close + close *1.47 /100
pos3 = close + close *3.3 /100
pos4 = close - close *0.49 /100
pos5 = close - close *1.47 /100
pos6 = close - close *3.3 /100
c = ta.pivothigh(leftLenH, rightLenH)
b = ta.pivotlow(leftLenL, rightLenL)
plotshape(c ? pos1: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos2: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos3: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos4: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos5: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos6: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
//
long_short = 0
long_last = c and (nz(long_short[1]) == 0 or nz(long_short[1]) == -1)
short_last = b and (nz(long_short[1]) == 0 or nz(long_short[1]) == 1)
long_short := long_last ? 1 : short_last ? -1 : long_short[1]
//Logic
longPrice = ta.valuewhen(long_last, close, 0)
shortPrice = ta.valuewhen(short_last, close, 0)
//Fixed liquidation
longStop = longPrice * (1 + (0.49/100))
longStop2 = longPrice * (1 + (1.47/100))
longStop3 = longPrice * (1 + (3.3/100))
ShortStop1 = shortPrice * (1 - (0.49/100))
ShortStop2 = shortPrice * (1 - (1.47/100))
ShortStop3 = shortPrice * (1 - (3.3/100))
//plot sltp lines
plot(long_short == 1 ? longStop :na , style=plot.style_linebr, color=color.blue, linewidth=1, title="100x Линия Лонг", trackprice=true)
plot(long_short == 1 ? longStop2 :na, style=plot.style_linebr, color=color.black, linewidth=1, title="50x Линия Лонг", trackprice=true)
plot(long_short == 1 ? longStop3 : na, style=plot.style_linebr, color=color.red, linewidth=1, title="25x Линия Лонг", trackprice=true)
plot(long_short == -1 ? ShortStop1 : na, style=plot.style_linebr, color=color.blue, linewidth=1, title="100x Линия Шорт", trackprice=true)
plot(long_short == -1 ? ShortStop2 : na, style=plot.style_linebr, color=color.black, linewidth=1, title="100x Линия Шорт", trackprice=true)
plot(long_short == -1 ? ShortStop3 : na, style=plot.style_linebr, color=color.red, linewidth=1, title="100x Линия Шорт", trackprice=true)
你可以使用 line
,我认为这会更容易。
但是,由于您特别要求地块,您可以在价格超过您的线时将 na
分配给您的地块。
这里有一个例子,它绘制了上个月的高点,当价格穿过它时,它停止绘制这条线。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
indicator("My script", overlay=true)
prev_month_high = request.security(syminfo.tickerid, "M", high[1], barmerge.gaps_on, barmerge.lookahead_on)
var float high_line = na
high_line := not na(prev_month_high) ? prev_month_high : high_line // Assign new previous high when it is a new month
is_high_cross = ta.cross(high, high_line)
is_low_cross = ta.cross(low, high_line)
high_line := (is_high_cross or is_low_cross) ? na : high_line // Assign na when the price crosses the line
plot(high_line, style=plot.style_linebr)
pos1 = close + close * (0.48 /100)
pos2 = close + close * (1.47 /100)
pos3 = close + close * (3.3 /100)
pos4 = close - close * (0.49 /100)
pos5 = close - close * (1.47 /100)
pos6 = close - close * (3.3 /100)
c = ta.pivothigh(leftLenH,rightLenH)
b = ta.pivotlow(leftLenL, rightLenL)
plotshape(c ? pos1: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos2: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos3: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos4: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos5: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos6: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
//////Lines//////////
bars = +500
n = 1
var line[] highs = array.new_line() // declare an empty array to store our lines in
var line[] highs2 = array.new_line() // declare an empty array to store our lines in
var line[] highs3 = array.new_line() // declare an empty array to store our lines in
var line[] highs4 = array.new_line() // declare an empty array to store our lines in
var line[] highs5 = array.new_line() // declare an empty array to store our lines in
var line[] highs6 = array.new_line() // declare an empty array to store our lines in
//Lines
bull = b
bear = c
highestHigh = pos1
highestHigh2 = pos2
highestHigh3 = pos3
lowerlow1 = pos4
lowerlow2 = pos5
lowerlow3 = pos6
if bear // instead of just drawing a line, we push it into an array, a list of lines so we can loop through the list and perform actions on all lines
array.unshift(highs, line.new(bar_index, highestHigh, bar_index + bars, highestHigh, extend=extend.none, color=color.red))
array.unshift(highs2, line.new(bar_index, highestHigh2, bar_index + bars, highestHigh2, extend=extend.none, color=color.red))
array.unshift(highs3, line.new(bar_index, highestHigh3, bar_index + bars, highestHigh3, extend=extend.none, color=color.red))
if bull
array.unshift(highs4, line.new(bar_index, lowerlow1, bar_index + bars, lowerlow1, extend=extend.none, color=color.red))
array.unshift(highs5, line.new(bar_index, lowerlow2, bar_index + bars, lowerlow2, extend=extend.none, color=color.red))
array.unshift(highs6, line.new(bar_index, lowerlow3, bar_index + bars, lowerlow3, extend=extend.none, color=color.red))
for i = (array.size(highs) > 0 ? array.size(highs)-1 : na) to 0
l1 = line.get_price(array.get(highs,i), bar_index)
if close > l1
line.set_x2(array.get(highs,i), bar_index)
array.remove(highs, i)
for i2 = (array.size(highs2) > 0 ? array.size(highs2)-1 : na) to 0
l2 = line.get_price(array.get(highs2,i2), bar_index)
if close > l2
line.set_x2(array.get(highs2,i2), bar_index)
array.remove(highs2, i2)
for i3 = (array.size(highs3) > 0 ? array.size(highs3)-1 : na) to 0
l3 = line.get_price(array.get(highs3,i3), bar_index)
if close > l3
line.set_x2(array.get(highs3,i3), bar_index)
array.remove(highs3, i3)
for i4 = (array.size(highs4) > 0 ? array.size(highs4)-1 : na) to 0
l4 = line.get_price(array.get(highs4,i4), bar_index)
if low > l4
line.set_x2(array.get(highs4,i4), bar_index)
array.remove(highs4, i4)
for i5 = (array.size(highs5) > 0 ? array.size(highs5)-1 : na) to 0
l5 = line.get_price(array.get(highs5,i5), bar_index)
if low > l5
line.set_x2(array.get(highs5,i5), bar_index)
array.remove(highs5, i5)
for i6 = (array.size(highs6) > 0 ? array.size(highs6)-1 : na) to 0
l6 = line.get_price(array.get(highs6,i6), bar_index)
if low > l6
line.set_x2(array.get(highs6,i6), bar_index)
array.remove(highs6, i6)
for x = (array.size(highs) > 0 ? array.size(highs)-1 : na) to 0
line.set_x2(array.get(highs, x), bar_index+bars)
for x2 = (array.size(highs2) > 0 ? array.size(highs2)-1 : na) to 0
line.set_x2(array.get(highs2, x2), bar_index+bars)
for x3 = (array.size(highs3) > 0 ? array.size(highs3)-1 : na) to 0
line.set_x2(array.get(highs3, x3), bar_index+bars)
for x4 = (array.size(highs4) > 0 ? array.size(highs4)-1 : na) to 0
line.set_x2(array.get(highs4, x4), bar_index+bars)
for x5 = (array.size(highs5) > 0 ? array.size(highs5)-1 : na) to 0
line.set_x2(array.get(highs5, x5), bar_index+bars)
for x6 = (array.size(highs6) > 0 ? array.size(highs6)-1 : na) to 0
line.set_x2(array.get(highs6, x6), bar_index+bars)
意识到线条看起来更合适,我稍微重写了代码。因此,出于某种原因,部分点我有一条线,有些没有,我不太清楚我哪里有错误......但是在回测中,这些线按它们应该的方式工作,除了较低的那些。问题很可能出在论证本身
我有一个问题,我想要线图,在穿过蜡烛时停止并且没有在图表上向右移动,而那些没有与蜡烛交叉的线不断走向正确的。是否可以用 Plot 做到这一点?
lengthGroupTitle = "Настройка уровней"
leftLenH = input.int(title="Множитель уровня ликвидации, относительно ТФ", defval=100, minval=1, group=lengthGroupTitle)
rightLenH = leftLenH
leftLenL = leftLenH
rightLenL = leftLenL
ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
drawLabel(_offset, _pivot, _style, _color, _textColor) =>
if not na(_pivot)
label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)
atr1 = ta.atr(10)
atr2 = ta.atr(10)
atr3 = ta.atr(10)
atr4 = ta.atr(10)
perc_dist4 = int(0.3)
atr5 = ta.atr(10)
perc_dist5 = int(1.2)
atr6 = ta.atr(10)
perc_dist6 = int(3)
pos1 = close + close *0.49 /100
pos2 = close + close *1.47 /100
pos3 = close + close *3.3 /100
pos4 = close - close *0.49 /100
pos5 = close - close *1.47 /100
pos6 = close - close *3.3 /100
c = ta.pivothigh(leftLenH, rightLenH)
b = ta.pivotlow(leftLenL, rightLenL)
plotshape(c ? pos1: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos2: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos3: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos4: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos5: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos6: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
//
long_short = 0
long_last = c and (nz(long_short[1]) == 0 or nz(long_short[1]) == -1)
short_last = b and (nz(long_short[1]) == 0 or nz(long_short[1]) == 1)
long_short := long_last ? 1 : short_last ? -1 : long_short[1]
//Logic
longPrice = ta.valuewhen(long_last, close, 0)
shortPrice = ta.valuewhen(short_last, close, 0)
//Fixed liquidation
longStop = longPrice * (1 + (0.49/100))
longStop2 = longPrice * (1 + (1.47/100))
longStop3 = longPrice * (1 + (3.3/100))
ShortStop1 = shortPrice * (1 - (0.49/100))
ShortStop2 = shortPrice * (1 - (1.47/100))
ShortStop3 = shortPrice * (1 - (3.3/100))
//plot sltp lines
plot(long_short == 1 ? longStop :na , style=plot.style_linebr, color=color.blue, linewidth=1, title="100x Линия Лонг", trackprice=true)
plot(long_short == 1 ? longStop2 :na, style=plot.style_linebr, color=color.black, linewidth=1, title="50x Линия Лонг", trackprice=true)
plot(long_short == 1 ? longStop3 : na, style=plot.style_linebr, color=color.red, linewidth=1, title="25x Линия Лонг", trackprice=true)
plot(long_short == -1 ? ShortStop1 : na, style=plot.style_linebr, color=color.blue, linewidth=1, title="100x Линия Шорт", trackprice=true)
plot(long_short == -1 ? ShortStop2 : na, style=plot.style_linebr, color=color.black, linewidth=1, title="100x Линия Шорт", trackprice=true)
plot(long_short == -1 ? ShortStop3 : na, style=plot.style_linebr, color=color.red, linewidth=1, title="100x Линия Шорт", trackprice=true)
你可以使用 line
,我认为这会更容易。
但是,由于您特别要求地块,您可以在价格超过您的线时将 na
分配给您的地块。
这里有一个例子,它绘制了上个月的高点,当价格穿过它时,它停止绘制这条线。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
indicator("My script", overlay=true)
prev_month_high = request.security(syminfo.tickerid, "M", high[1], barmerge.gaps_on, barmerge.lookahead_on)
var float high_line = na
high_line := not na(prev_month_high) ? prev_month_high : high_line // Assign new previous high when it is a new month
is_high_cross = ta.cross(high, high_line)
is_low_cross = ta.cross(low, high_line)
high_line := (is_high_cross or is_low_cross) ? na : high_line // Assign na when the price crosses the line
plot(high_line, style=plot.style_linebr)
pos1 = close + close * (0.48 /100)
pos2 = close + close * (1.47 /100)
pos3 = close + close * (3.3 /100)
pos4 = close - close * (0.49 /100)
pos5 = close - close * (1.47 /100)
pos6 = close - close * (3.3 /100)
c = ta.pivothigh(leftLenH,rightLenH)
b = ta.pivotlow(leftLenL, rightLenL)
plotshape(c ? pos1: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos2: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(c ? pos3: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos4: na , "100х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "100х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos5: na , "50х Ликвилации Лонг", shape.circle, location.absolute, color.black, 0, "50х Ликвидации", (color.black), size=size.tiny)
plotshape(b ? pos6: na , "25х Ликвидации Лонг", shape.circle, location.absolute, color.black, 0, "25х Ликвидации", (color.black), size=size.tiny)
//////Lines//////////
bars = +500
n = 1
var line[] highs = array.new_line() // declare an empty array to store our lines in
var line[] highs2 = array.new_line() // declare an empty array to store our lines in
var line[] highs3 = array.new_line() // declare an empty array to store our lines in
var line[] highs4 = array.new_line() // declare an empty array to store our lines in
var line[] highs5 = array.new_line() // declare an empty array to store our lines in
var line[] highs6 = array.new_line() // declare an empty array to store our lines in
//Lines
bull = b
bear = c
highestHigh = pos1
highestHigh2 = pos2
highestHigh3 = pos3
lowerlow1 = pos4
lowerlow2 = pos5
lowerlow3 = pos6
if bear // instead of just drawing a line, we push it into an array, a list of lines so we can loop through the list and perform actions on all lines
array.unshift(highs, line.new(bar_index, highestHigh, bar_index + bars, highestHigh, extend=extend.none, color=color.red))
array.unshift(highs2, line.new(bar_index, highestHigh2, bar_index + bars, highestHigh2, extend=extend.none, color=color.red))
array.unshift(highs3, line.new(bar_index, highestHigh3, bar_index + bars, highestHigh3, extend=extend.none, color=color.red))
if bull
array.unshift(highs4, line.new(bar_index, lowerlow1, bar_index + bars, lowerlow1, extend=extend.none, color=color.red))
array.unshift(highs5, line.new(bar_index, lowerlow2, bar_index + bars, lowerlow2, extend=extend.none, color=color.red))
array.unshift(highs6, line.new(bar_index, lowerlow3, bar_index + bars, lowerlow3, extend=extend.none, color=color.red))
for i = (array.size(highs) > 0 ? array.size(highs)-1 : na) to 0
l1 = line.get_price(array.get(highs,i), bar_index)
if close > l1
line.set_x2(array.get(highs,i), bar_index)
array.remove(highs, i)
for i2 = (array.size(highs2) > 0 ? array.size(highs2)-1 : na) to 0
l2 = line.get_price(array.get(highs2,i2), bar_index)
if close > l2
line.set_x2(array.get(highs2,i2), bar_index)
array.remove(highs2, i2)
for i3 = (array.size(highs3) > 0 ? array.size(highs3)-1 : na) to 0
l3 = line.get_price(array.get(highs3,i3), bar_index)
if close > l3
line.set_x2(array.get(highs3,i3), bar_index)
array.remove(highs3, i3)
for i4 = (array.size(highs4) > 0 ? array.size(highs4)-1 : na) to 0
l4 = line.get_price(array.get(highs4,i4), bar_index)
if low > l4
line.set_x2(array.get(highs4,i4), bar_index)
array.remove(highs4, i4)
for i5 = (array.size(highs5) > 0 ? array.size(highs5)-1 : na) to 0
l5 = line.get_price(array.get(highs5,i5), bar_index)
if low > l5
line.set_x2(array.get(highs5,i5), bar_index)
array.remove(highs5, i5)
for i6 = (array.size(highs6) > 0 ? array.size(highs6)-1 : na) to 0
l6 = line.get_price(array.get(highs6,i6), bar_index)
if low > l6
line.set_x2(array.get(highs6,i6), bar_index)
array.remove(highs6, i6)
for x = (array.size(highs) > 0 ? array.size(highs)-1 : na) to 0
line.set_x2(array.get(highs, x), bar_index+bars)
for x2 = (array.size(highs2) > 0 ? array.size(highs2)-1 : na) to 0
line.set_x2(array.get(highs2, x2), bar_index+bars)
for x3 = (array.size(highs3) > 0 ? array.size(highs3)-1 : na) to 0
line.set_x2(array.get(highs3, x3), bar_index+bars)
for x4 = (array.size(highs4) > 0 ? array.size(highs4)-1 : na) to 0
line.set_x2(array.get(highs4, x4), bar_index+bars)
for x5 = (array.size(highs5) > 0 ? array.size(highs5)-1 : na) to 0
line.set_x2(array.get(highs5, x5), bar_index+bars)
for x6 = (array.size(highs6) > 0 ? array.size(highs6)-1 : na) to 0
line.set_x2(array.get(highs6, x6), bar_index+bars)
意识到线条看起来更合适,我稍微重写了代码。因此,出于某种原因,部分点我有一条线,有些没有,我不太清楚我哪里有错误......但是在回测中,这些线按它们应该的方式工作,除了较低的那些。问题很可能出在论证本身