英文:
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.
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.
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
,然后使用您的时间戳来设置left
和right
。
以下示例显示了如何操作:
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] < end) and (time >= 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论