从今年的最高点到今天的 PineScript 画一条线
Draw A Line From This Years Highest High To Today PineScript
我正在学习 pinescript 并在我的 if 语句中遇到编译错误
“预计行尾没有行继续。”
我想要代码做的是创建 2 行
- 从今年的最高点到收盘蜡烛
- 从今年的最低点到收盘蜡烛
@version=4
strategy("Time Range", overlay=true)
i_startTime=input(defval=timestamp("01 Jan 2021 13:30 +0000"), title="Start Time", type=input.time)
i_endTime=input(defval=timestamp("01 Jul 2021 13:30 +0000"), title="End Time", type=input.time)
i_length=input(defval=20, title= "Length", type=input.integer)
inDateRange = time >= i_startTime and time <= i_endTime
inCondition = not na(close[i_length])
hh=highest(high,i_length)
ll=lowest(low,i_length)
if(inCondition and inDateRange)
// Make both trend lines just once
highLine = line.new(x1=bar_index[hh], y1=close[hh],
x2=bar_index, y2=close, color=color.green,
extend=extend.both)
lowLine = line.new(x1=bar_index[ll], y1=close[ll],
x2=bar_index, y2=close, color=color.red,
extend=extend.both)
首先,它应该是 //@version=4
并且您不必要地缩进了所有代码。
newYear = change(time("12M")) != 0
var float hh = na
var float ll = na
var int hhIndex = na
var int llIndex = na
var line hhLine = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.red)
var line llLine = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.green)
if newYear
hh := high
ll := low
hhIndex := bar_index
llIndex := bar_index
if not newYear
if high > hh
hh := high
hhIndex := bar_index
line.set_xy1(hhLine, x = hhIndex, y = hh)
line.set_xy2(hhLine, x = hhIndex + 1, y = hh)
if low < ll
ll := low
llIndex := bar_index
line.set_xy1(llLine, x = llIndex, y = ll)
line.set_xy2(llLine, x = llIndex + 1, y = ll)
if barstate.isconfirmed
line.set_x2(hhLine, x = bar_index + 1)
line.set_x2(llLine, x = bar_index + 1)
请注意,除非线条的原点坐标位于已加载的图表块内,否则线条不会加载。根据您的时间范围,这可能意味着它们不会出现,除非您及时回溯并检索到新块。在这种情况下,最好只使用 plot :
plot(hh)
plot(ll)
我正在学习 pinescript 并在我的 if 语句中遇到编译错误 “预计行尾没有行继续。”
我想要代码做的是创建 2 行
- 从今年的最高点到收盘蜡烛
- 从今年的最低点到收盘蜡烛
@version=4 strategy("Time Range", overlay=true) i_startTime=input(defval=timestamp("01 Jan 2021 13:30 +0000"), title="Start Time", type=input.time) i_endTime=input(defval=timestamp("01 Jul 2021 13:30 +0000"), title="End Time", type=input.time) i_length=input(defval=20, title= "Length", type=input.integer) inDateRange = time >= i_startTime and time <= i_endTime inCondition = not na(close[i_length]) hh=highest(high,i_length) ll=lowest(low,i_length) if(inCondition and inDateRange) // Make both trend lines just once highLine = line.new(x1=bar_index[hh], y1=close[hh], x2=bar_index, y2=close, color=color.green, extend=extend.both) lowLine = line.new(x1=bar_index[ll], y1=close[ll], x2=bar_index, y2=close, color=color.red, extend=extend.both)
首先,它应该是 //@version=4
并且您不必要地缩进了所有代码。
newYear = change(time("12M")) != 0
var float hh = na
var float ll = na
var int hhIndex = na
var int llIndex = na
var line hhLine = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.red)
var line llLine = line.new(x1 = na, y1 = na, x2 = na, y2 = na, color = color.green)
if newYear
hh := high
ll := low
hhIndex := bar_index
llIndex := bar_index
if not newYear
if high > hh
hh := high
hhIndex := bar_index
line.set_xy1(hhLine, x = hhIndex, y = hh)
line.set_xy2(hhLine, x = hhIndex + 1, y = hh)
if low < ll
ll := low
llIndex := bar_index
line.set_xy1(llLine, x = llIndex, y = ll)
line.set_xy2(llLine, x = llIndex + 1, y = ll)
if barstate.isconfirmed
line.set_x2(hhLine, x = bar_index + 1)
line.set_x2(llLine, x = bar_index + 1)
请注意,除非线条的原点坐标位于已加载的图表块内,否则线条不会加载。根据您的时间范围,这可能意味着它们不会出现,除非您及时回溯并检索到新块。在这种情况下,最好只使用 plot :
plot(hh)
plot(ll)