var line extend right but cut off on candle

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

var line extend right but cut off on candle

问题

I created an intraday Fibonacci indicator but got stuck on the "var" line because I'm new to using the "var" line and have been using "plot" instead. I'm trying to make the line stop at the candle and only extend when a new candle forms. Currently, I am using "extend to the right," which gives me the result shown in the image Extend Right. Without extending to the right, it looks like this: No Extend Right. Is there a way for the line to stop at the last candle and update when a new candle forms?

英文:

I created a intraday fibonnaci but just stuck on the var line as I'm new to using var line and have been using plot instead.

I'm trying to get the line to cut off at the candle and only extend when a new candle is from, I am using extend to right at the moment which gives me the below result

[Extend Right][1]: https://i.stack.imgur.com/VggLQ.png

Without extend right, it looks like this

[no extend right][2]: https://i.stack.imgur.com/wt3jf.png

Is there a way for the line to create itself and stop at the last candle and update once a new candle is form?

//@version=5

indicator(title='Auto Intraday Fibonnaci', overlay=true)

line_width = input.int(title="Line Width", defval=2, minval=1, maxval=100)

Fhigh = request.security(syminfo.tickerid, 'D', high)
Flow = request.security(syminfo.tickerid, 'D', low)

F0 = Flow
F236 = (Fhigh - Flow) * 0.236 + Flow
F382 = (Fhigh - Flow) * 0.382 + Flow
F500 = (Fhigh - Flow) * 0.500 + Flow
F618 = (Fhigh - Flow) * 0.618 + Flow
F786 = (Fhigh - Flow) * 0.786 + Flow
F1000 = (Fhigh - Flow) * 1.000 + Flow

f_newLine(_color) => line.new(na, na, na, na, xloc.bar_time, extend.right, color=_color, width=line_width)

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x,   _y)
    line.set_xy2(_line, _x+1, _y)

var line    line_0 = f_newLine(color.gray)
var line    line_236 = f_newLine(color.gray)
var line    line_382 = f_newLine(color.gray)
var line    line_500 = f_newLine(color.orange)
var line    line_618 = f_newLine(color.orange)
var line    line_786 = f_newLine(color.gray)
var line    line_1000 = f_newLine(color.gray)

[t0,t236,t382,t500,t618,t786,t1000,dt] = request.security(syminfo.tickerid,"D", [F0,F236,F382,F500,F618,F786,F1000,time], lookahead=barmerge.lookahead_on)

if barstate.islast
    f_moveLine(line_0, dt, t0)
    f_moveLine(line_236, dt, t236)
    f_moveLine(line_382, dt, t382)
    f_moveLine(line_500, dt, t500)
    f_moveLine(line_618, dt, t618)
    f_moveLine(line_786, dt, t786)
    f_moveLine(line_1000, dt, t1000)

plotshape(F0 ? F0 : na, style=shape.circle, location=location.absolute, color=color.rgb(120, 123, 134, 100), textcolor=color.new(color.gray, 0), show_last=1, text='0.000', offset=5)
plotshape(F236 ? F236 : na, style=shape.circle, location=location.absolute, color=color.rgb(120, 123, 134, 100), textcolor=color.new(color.gray, 0), show_last=1, text='0.236', offset=5)
plotshape(F382 ? F382 : na, style=shape.circle, location=location.absolute, color=color.rgb(120, 123, 134, 100), textcolor=color.new(color.gray, 0), show_last=1, text='0.382', offset=5)
plotshape(F500 ? F500 : na, style=shape.circle, location=location.absolute, color=color.rgb(255, 235, 59, 100), textcolor=color.new(color.orange, 0), show_last=1, text='0.500', offset=5)
plotshape(F618 ? F618 : na, style=shape.circle, location=location.absolute, color=color.rgb(255, 235, 59, 100), textcolor=color.new(color.orange, 0), show_last=1, text='0.618', offset=5)
plotshape(F786 ? F786 : na, style=shape.circle, location=location.absolute, color=color.rgb(120, 123, 134, 100), textcolor=color.new(color.gray, 0), show_last=1, text='0.786', offset=5)
plotshape(F1000 ? F1000 : na, style=shape.circle, location=location.absolute, color=color.rgb(120, 123, 134, 100), textcolor=color.new(color.gray, 0), show_last=1, text='1.000', offset=5)

答案1

得分: 0

这是可能的,使用 chart.right_visible_bar_time。我更新了您的代码中的以下行,现在似乎按您的要求工作了。

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x, _y)
    line.set_xy2(_line, chart.right_visible_bar_time, _y)
英文:

This is possible using chart.right_visible_bar_time. I updated the following line of your code and it seems to be working as you desire now.

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x,   _y)
    line.set_xy2(_line, chart.right_visible_bar_time, _y)

huangapple
  • 本文由 发表于 2023年5月11日 02:23:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221552.html
匿名

发表评论

匿名网友

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

确定