使用时间戳绘制框。

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

Drawing box using timestamp

问题

以下是翻译好的部分:

"As title says im trying to plot a box using 2 timestamps (start and stop). Considering the High and Low inside this range.

Here an image:
使用时间戳绘制框。

Well i tried to do something but im stuck with the dates. For now i use an int box to go back to the date, but its a bit complicated when change timeframe.

Here's the code:

//@version=5
indicator('Test Box', overlay=true)

lenght = input.int(200, title='Lenght')
show = input.bool(true, title='Show Box')

lowPrice = ta.lowest(low, lenght)
highPrice = ta.highest(high, lenght)

if barstate.ishistory

if show
_Bot = line.new(bar_index[lenght], lowPrice, bar_index, lowPrice)
_Top = line.new(bar_index[lenght], highPrice, bar_index, highPrice)
_Left = line.new(bar_index[lenght], highPrice, bar_index[lenght], lowPrice)
_Right = line.new(bar_index, highPrice, bar_index, lowPrice)

line.delete(_Bot1)
line.delete(_Top1)
line.delete(_Left1)
line.delete(_Right1)

Any suggestion to get the result displayed in image but using timestamps form start and end date?"

英文:

As title says im trying to plot a box using 2 timestamps (start and stop).
Considering the High and Low inside this range.

Here an image:
使用时间戳绘制框。

Well i tried to do something but im stuck with the dates. For now i use an int box to go back to the date, but its a bit complicated when change timeframe.

Here's the code:

//@version=5
indicator('Test Box', overlay=true)

lenght = input.int(200,    title='Lenght')
show   = input.bool(true,  title='Show Box')

lowPrice  = ta.lowest(low,   lenght)
highPrice = ta.highest(high, lenght)

if barstate.ishistory
  
   if show
      _Bot   = line.new(bar_index[lenght], lowPrice,  bar_index,         lowPrice)
      _Top   = line.new(bar_index[lenght], highPrice, bar_index,         highPrice)
      _Left  = line.new(bar_index[lenght], highPrice, bar_index[lenght], lowPrice)
      _Right = line.new(bar_index,         highPrice, bar_index,         lowPrice)

      line.delete(_Bot[1])
      line.delete(_Top[1])
      line.delete(_Left[1])
      line.delete(_Right[1])

Any suggestion to get the result displayed in image but using timestamps form start and end date?

答案1

得分: 1

box.new()有一个名为xloc的参数。您可以将其设置为xloc.bar_time,然后使用您的时间戳来设置leftright

以下示例显示了如何操作:

start = timestamp(2023, 01, 01, 00, 00)
end = timestamp(2023, 01, 15, 00, 00)

draw_box = (time[1] < end) and (time >= end)    // 仅在到达结束日期时绘制框

if (draw_box)
    box.new(start, high, end, low, xloc=xloc.bar_time)

然后,您只需找到顶部和底部的范围。

英文:

box.new() has an argument called xloc. You can set it to xloc.bar_time and then use your timestamps for the left and right.

Below example shows you how to do that:

start = timestamp(2023, 01, 01, 00, 00)
end = timestamp(2023, 01, 15, 00, 00)

draw_box = (time[1] &lt; end) and (time &gt;= end)    // Only draw the box when the end date is reached

if (draw_box)
    box.new(start, high, end, low, xloc=xloc.bar_time)

You then just need to find the top and bottom range.

huangapple
  • 本文由 发表于 2023年6月5日 17:21:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405029.html
匿名

发表评论

匿名网友

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

确定