pine-script - Pine Script - 在任何先前 session 的特定时间范围的最高点绘制水平线,无论我当前的 session 如何

标签 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

Sample Image

最佳答案

下午, 我更新了我的交易 View 时间范围(右下角)以反射(reflect)交易品种信息 (+5:30)。

enter image description here

 //@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")

##########更新答案##############

您可以在设置中选择您想要查看的日期。

enter image description here

//@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")

关于pine-script - Pine Script - 在任何先前 session 的特定时间范围的最高点绘制水平线,无论我当前的 session 如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67228523/

相关文章:

c# - 将 RSI 从 pinescript 转换为 C#?

python - pine 脚本如何使用 2 系列而不是 1 和一个周期来计算 RSI?

pine-script - Pinescript 中的 sleep /暂停功能

pine-script - 为什么即使我使用市价订单,松树脚本也会在下一个蜡烛开盘时输入?

pine-script - 松脚本 : Is there a way to hide specific indicator values from the data window?

pine-script - 为什么我收到错误 : could not find function or function reference 'study' ?

pine-script - 如何在松脚本中使用杠杆

pine-script - 将字符串转换为 Float Pine 脚本

pine-script - Pine Script (TradingView) 颜色高于最高点

pine-script - TradingView – Pine Script 中单个订单的多个止盈