pine-script - Pine Script - 在任何先前会话的特定时间范围的最高点绘制水平线,无论我当前会话如何
问题描述
我需要帮助才能达到过去时间范围的最高点。时间范围是通过日期时间选择器选择的。
下面的代码提供了选择开始时间和结束时间的选项。选择时间范围后,它会在图表上突出显示该时间范围的背景。我无法编码的是获得这个突出显示的时间范围的最高值。
//@version=4
study("Price Channel with date range", overlay=true)
i_startTime = input(defval = timestamp("23 Apr 2021 04:45 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("23 Apr 2021 05:00 +0000"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
bgcolor(inDateRange ? color.lime : na, 50)
// To DO -- Get the high of this time range
// the time difference here is 15 minute, I need the high of this 15 minute time frame plotted automatically when I select the start time and end time
// I have drawn a line at the high of this time range manually
解决方案
下午,我更新了我的交易视图时间框架(右下角)以反映交易品种信息(+5:30)。
//@version=4
study("Trading View", overlay=true)
// User adjustment inputs
offset_val = input(title="Label Offset", type=input.integer, defval=20)
// Asia Start
time_int_01 = input("1015-1030:1234567", "Time", input.session)
in_time_int_01 = time(timeframe.period, time_int_01)
var highe_01 = 0.0
var lowe_01 = 10e10
if in_time_int_01
if not in_time_int_01[1]
highe_01 := high
else
highe_01 := max(high, highe_01)
plot(not in_time_int_01 ? highe_01 : na, title="High", color=color.purple, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_01 ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="High", offset = offset_val, transp=20, title="High")
###########已更新答案###############
您可以选择您希望在设置中看到的日期。
//@version=4
study("Trading View", overlay=true)
// User adjustment inputs
offset_val = input(title="Label Offset", type=input.integer, defval=20)
// Monday High
time_int_02 = input("1015-1030:2", "Monday", input.session)
in_time_int_02 = time(timeframe.period, time_int_02)
var highe_02 = 0.0
var lowe_02 = 10e10
if in_time_int_02
if not in_time_int_02[1]
highe_02 := high
else
highe_02 := max(high, highe_02)
plot(not in_time_int_02 ? highe_02 : na, title="Monday High", color=color.purple, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_02 ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Monday High", offset = offset_val, transp=20, title="Monday High")
// Tuesday High
time_int_03 = input("1015-1030:3", "Tuesday", input.session)
in_time_int_03 = time(timeframe.period, time_int_03)
var highe_03 = 0.0
var lowe_03 = 10e10
if in_time_int_03
if not in_time_int_03[1]
highe_03 := high
else
highe_03 := max(high, highe_03)
plot(not in_time_int_03 ? highe_03 : na, title="Tuesday High", color=color.blue, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_03 ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="Tuesday High", offset = offset_val, transp=20, title="Tuesday High")
// Wednesday High
time_int_04 = input("1015-1030:4", "Wednesday", input.session)
in_time_int_04 = time(timeframe.period, time_int_04)
var highe_04 = 0.0
var lowe_04 = 10e10
if in_time_int_04
if not in_time_int_04[1]
highe_04 := high
else
highe_04 := max(high, highe_04)
plot(not in_time_int_04 ? highe_04 : na, title="Wednesday High", color=color.orange, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_04 ? highe_04 : na, style=shape.labelup, location=location.absolute, color=color.orange, textcolor=color.white, show_last=1, text="Wednesday High", offset = offset_val, transp=20, title="Wednesday High")
// Thursday High
time_int_05 = input("1015-1030:5", "Thursday", input.session)
in_time_int_05 = time(timeframe.period, time_int_05)
var highe_05 = 0.0
var lowe_05 = 10e10
if in_time_int_05
if not in_time_int_05[1]
highe_05 := high
else
highe_05 := max(high, highe_05)
plot(not in_time_int_05 ? highe_05 : na, title="Thursday High", color=color.green, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_05 ? highe_05 : na, style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, show_last=1, text="Thursday High", offset = offset_val, transp=20, title="Thursday High")
// Friday High
time_int_06 = input("1015-1030:6", "Friday", input.session)
in_time_int_06 = time(timeframe.period, time_int_06)
var highe_06 = 0.0
var lowe_06 = 10e10
if in_time_int_06
if not in_time_int_06[1]
highe_06 := high
else
highe_06 := max(high, highe_06)
plot(not in_time_int_06 ? highe_06 : na, title="Friday High", color=color.white, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_06 ? highe_06 : na, style=shape.labelup, location=location.absolute, color=color.white, textcolor=color.black, show_last=1, text="Friday High", offset = offset_val, transp=20, title="Friday High")
根据您的评论问题进行硬编码:
当前代码:
time_int_02 = input("1015-1030:2", "Monday", input.session)
in_time_int_02 = time(timeframe.period, time_int_02)
删除第一行并将时间移至第二行:
in_time_int_02 = time(timeframe.period, "1015-1030:2")
推荐阅读
- docker - 从 Docker GitHub Action 将二进制文件添加到 PATH 以供以后的工作流程步骤使用
- javascript - 如何通过状态传递数组项
- elasticsearch - 从聚合结果中求和 doc_count - 错误“buckets_path 不存在用于聚合
- ios - iOS Game Center GKScore 上下文,如何编码信息?
- google-apps-script - Google Sheet GAS中过滤方法的字符串部分匹配
- r - 通过带有 facet wrap 的特定变量重新排序 geom_bar
- promise - 方法链有自我意识吗?
- python - 从 python 程序中保存多个输入的文件读取问题
- google-sheets - Google Sheets 图表中的绝对引用
- sqlite - 将图像绑定到 CarouselView