December 1, 2020
New Parameter for Date Input Added to Pine

Entering dates and times in Pine has become much easier, because the input() function can now accept the new input.time type. With this parameter, you can transfer a date to Pine using the Settings dialog and the same date and time widget used throughout the TradingView user interface.

The time for input.time is set in Unix format, but for the convenience of setting the initial date value, we’ve added the ability to pass constant strings containing a date in one of several common formats to the timestamp() function and specify the call to this function as a devfal parameter of the input() function. In the timestamp() function, you can specify the time in any convenient time zone, and the value will automatically adjust to the time zone selected on the chart. For example, if you create a strategy that will open trades only after a specific date and for this you pass the value timestamp(“01 Sep 2020 13:30 +0000″), on a chart with the time zone UTC-5 (New York) it will start trading on a candle at 8:30 AM (in winter) or 9:30 AM (in summer).

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 ? : na, 90)

Learn more about timestamp() and input() functions in the Pine Script reference.

We hope you find this often-requested feature useful. Please continue to send us your feedback and suggestions. We’re building TradingView for you, and we’re excited to hear what you think about our platform updates.

The fastest way to follow markets

Launch Chart