7.1 Timeframes and Resolution
In Pinescript, you can work with different timeframes and resolutions for your script. The security() function allows you to retrieve data from a specific symbol and resolution:
higherTimeframeClose = request.security(syminfo.tickerid, "2H", close)
7.2 Timestamps and Time Functions
Pinescript provides several functions to work with timestamps and time-based conditions. Some useful functions include:
- time: Returns the timestamp of the current bar in Unix format.
- year, month, day, hour, minute, second: Extract the respective date and time components from a timestamp.
For example, to check if the current bar is the first trading day of the month:
isNewMonth = month[1] != month
if isNewMonth
label.new(x=bar_index, y=high, text="New Month", color=color.blue, textcolor=color.white, style=label.style_label_down)
7.3 Formatting Dates and Times
You can format dates and times using the str.tostring() function in combination with the various time functions:
isNewMonth = month[1] != month
dateString = str.tostring(year) + "-" + str.tostring(month) + "-" + str.tostring(dayofmonth)
if isNewMonth
label.new(x=bar_index, y=high, text=dateString, color=color.blue, textcolor=color.white, style=label.style_label_down)
Comments
0 comments
Please sign in to leave a comment.