Asif Mulla
Asif Mulla

Reputation: 1664

User defined function returns series instead of value

I have defined user defined function in a pine script to get timestamp with respect to some date. But when executed it returns error as

Add to Chart operation failed, reason: line 35: Cannot call timestamp with arguments (series, series, literal integer, literal integer, literal integer);available overloads: timestamp(integer, integer, integer, integer, integer) => integer; timestamp(string, integer, integer, integer, integer, integer) => integer;

My Code Spec:

getdate() =>
    tt = timenow - 1549238400
    yr = year(tt)
    mt = month(tt)
    dt = dayofmonth(tt)
    timestamp(yr, mt, 01, 0, 0)

value = getdate()
plot(value, color = red, linewidth = 5, title = "27", style = histogram)

I am expecting 29 days ago date (4-Feb-2019) from now (5-March-2019) for timestamp function. But somehow I am getting series, which results in an error.

Any help will be appreciated.

Upvotes: 0

Views: 458

Answers (1)

DmitriyK
DmitriyK

Reputation: 61

In the Pine v4 the timestamp() function can accept series, and you can get timestamp with respect to some date using this script:

//@version=4
study("My Script")
dayTms()=>
 yr = year(time)
 mt = month(time)
 dt = dayofmonth(time)
 timestamp(yr, mt, dt, 0, 0)

requiredDayTms(daysAgo) =>
 tt = timenow - 86400 * daysAgo * 1000
 yr = year(tt)
 mt = month(tt)
 dt = dayofmonth(tt)
 timestamp(yr, mt, dt, 0, 0)

// argument value is the indent (in days) from the current bar
d=requiredDayTms(5)
plot(d == dayTms() ? 1:0, color=color.red, style=plot.style_histogram, linewidth=5 )

Upvotes: 1

Related Questions