日期输入的新参数已添加到Pine

Dec 1, 2020

在Pine中输入日期和时间变得更加容易,因为 input() 函数现在可以接受新的 input.time 类型。使用此参数,您可以使用 设置 对话框和在整个TradingView用户界面中使用相同的日期和时间小插件,将日期传输到Pine。

input.time 的时间以Unix格式设置,但是为了方便设置初始日期值,我们添加了将包含几种常用格式之一的日期的常量字符串传递给 timestamp()  函数的功能,并将对此函数的调用指定为 input() 函数的 devfal 参数。在 timestamp() 函数中,您可以在任何方便的时区中指定时间,该值将自动调整为在图表上选择的时区。例如,如果您创建仅在特定日期之后才开盘交易的策略,并为此传递值 timestamp(“01 Sep 2020 13:30 +0000″) ,在时区UTC-5(纽约)的图表上,它将在8:30 AM(冬季)或9:30 AM(夏季)在K线上开始交易。

//@version=4
strategy("Price Channel Strategy with date range", overlay=true)

i_startTime = input(defval = timestamp("01 Sep 2020 13:30 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("30 Sep 2020 19:30 +0000"), title = "End Time", type = input.time)
i_length = input(defval = 20, title = "Length", type = input.integer)

inDateRange = time >= i_startTime and time <= i_endTime
inCondition = not na(close[i_length])

hh = highest(high, i_length)
ll = lowest(low, i_length)

if (inCondition and inDateRange)
    strategy.entry("PChLE", strategy.long, stop=hh)
    strategy.entry("PChSE", strategy.short, stop=ll)

bgcolor(inDateRange ? color.green : na, 90)

在Pine脚本参考手册中了解有关 timestamp() 和 input() 函数的更多信息。

我们希望您发现这项常被申请添加的功能有用。请继续向我们发送您的反馈和建议。我们正在为您打造TradingView,很高兴听到您对我们平台更新的看法。


 

还没有关注我们的中文微信公众号?快来扫二维码吧!

Look first Then leap

TradingView专门为您而打造,请确保您充分利用我们出色的功能
开启图表