[英]Pine Script - How to select a candle stick bar with date time picker and draw horizontal lines at the high and low of this bar
I am trying to draw hline (horizontal lines) at the high and low of a candle stick bar (15 minute time frame is a MUST) which I have selected from date time picker.我正在尝试在我从日期时间选择器中选择的蜡烛条的高点和低点绘制 hline(水平线)(必须 15 分钟的时间范围)。 As of now I can select the bar and highlight its background color to confirm that the date time picker is working fine.截至目前,我可以 select 栏并突出显示其背景颜色以确认日期时间选择器工作正常。 However I cannot draw horizontal lines at the high and low of this selected bar.但是,我无法在此选定条的高点和低点绘制水平线。 The issue here is, I don't know how to get the high and low of the bar which I have selected from date time picker.这里的问题是,我不知道如何获取我从日期时间选择器中选择的栏的高点和低点。 Below is the code.下面是代码。
//@version=4
study("Price Channel with date range test", overlay=true)
i_startTime = input(defval = timestamp("06 May 2021 04:30 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("06 May 2021 04:45 +0000"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
bgcolor(inDateRange ? color.lime : na, 90)
// Need code to get the high and low of this candle stick bar selected from the date time picker
Working Code.工作代码。
//@version=4
study("Price Channel with time range", overlay=true)
i_startTime = input(defval = timestamp("07 May 2021 04:30 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("07 May 2021 04:30 +0000"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
bgcolor(inDateRange ? color.lime : na, 90)
var highe_01 = 0.0
var lowe_01 = 0.0
if inDateRange
if not inDateRange[1]
highe_01 := high
lowe_01 := low
else
highe_01 := max(high, highe_01)
lowe_01 := min(low, lowe_01)
plot(not inDateRange ? highe_01 : na, title="High", color=color.purple, linewidth=2, style=plot.style_linebr, offset=-9999, trackprice=true)
plot(not inDateRange ? lowe_01: na, title="Low", color=color.purple, linewidth=2, style=plot.style_linebr, offset=-9999, trackprice=true)
The below gives you the option of having the lines to either: just to the right or across the whole chart (tick box in settings).下面为您提供了将线条设置为以下任一选项的选项:仅在右侧或整个图表(设置中的复选框)。
Is this what you are after?这就是你所追求的吗?
//@version=4
study("Price Channel with time range", overlay=true)
i_startTime = input(defval = timestamp("07 May 2021 04:30 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("07 May 2021 04:30 +0000"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
bgcolor(inDateRange ? color.lime : na, 90)
var highe_01 = 0.0
var lowe_01 = 0.0
if inDateRange
if not inDateRange[1]
highe_01 := high
lowe_01 := low
else
highe_01 := max(high, highe_01)
lowe_01 := min(low, lowe_01)
//plot(not inDateRange ? highe_01 : na, title="High", color=color.purple, linewidth=2, style=plot.style_linebr)
//plot(not inDateRange ? lowe_01: na, title="Low", color=color.purple, linewidth=2, style=plot.style_linebr)
///////////////////////////////
showHigh = input(true, title="High", group="High Line", inline="1")
showLow = input(true, title="Low", group="Low Line", inline="1")
ExtendAxisLine = input(false, title="Extend lines across screen")
ExtendOption = ExtendAxisLine ? extend.both : extend.right
HighDateLine = (not inDateRange ? highe_01 : na)
var line ShowHighLine = na
if showHigh
ShowHighLine := line.new(bar_index[1], HighDateLine, bar_index, HighDateLine, color=color.yellow, style=line.style_dashed, width=1, extend=ExtendOption)
line.delete(ShowHighLine[1])
LowDateLine = (not inDateRange ? lowe_01 : na)
var line ShowLowLine = na
if showLow
ShowLowLine := line.new(bar_index[1], LowDateLine, bar_index, LowDateLine, color=color.yellow, style=line.style_dashed, width=1, extend=ExtendOption)
line.delete(ShowLowLine[1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.