'Pine Script: How to be able to manually input values for specific dates

I'm trying to create an indicator where I can manually input values for specified dates.

For example, I want a value of 40 to be shown on the indicator on 12/1/2021, a value of 80 on 12/2/2021 and a value of 90 on 12/3/2021, and so forth.

I'm new to all this, but maybe describing the time in Pine Script for one of those dates would look like this (?):

if timestamp(2021, 12, 1, 0, 0) == close

I really don't know... is this even a possible task? I'm sure it is, but I have no idea how to figure this out. I would really appreciate any help.



Solution 1:[1]

You can use input.time() to manually input timestamps.

https://www.tradingview.com/pine-script-reference/v5/#fun_input{dot}time

//@version=5
indicator("time input", overlay = false)

ts1 = input.time(timestamp("Dec 1 2021 00:00 +000"), title = "Timestamp 1")
ts2 = input.time(timestamp("Dec 2 2021 00:00 +000"), title = "Timestamp 2")
ts3 = input.time(timestamp("Dec 3 2021 00:00 +000"), title = "Timestamp 3")

float val = na

if time == ts1
    val := 40

if time == ts2
    val := 80

if time == ts3
    val := 90

plot(val)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rumpypumpydumpy