Page 1 of 1

Add date to label

Posted: Fri Jul 02, 2021 11:22 am
by jimfred
I am trying to add the date to labels on every significant pivot on the chart. For example, the script PIVOT HILO prints the hi/lo value of the pivot on a label above or below the candle pivot. But I want to also include the date on the label.

Anyone have an idea how to grab the date, for this purpose?

Thanks...

Re: Add date to label

Posted: Sat Jul 03, 2021 1:01 pm
by CanYouCatchMe01
You can do this.
Image

I get the year as an integer and convert it to a string and then add the text on the label. I was not able to get the day. There is a variable called dayofmonth, but that seems to be another thing.

code:

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CanYouCatchMe

//@version=4
study("date pivot points", overlay=true)
prd = input(defval = 20, title="Pivot Point Period", minval = 10, maxval = 50)

float ph = na, float pl = na //If there is no pivit points. Default value
ph := pivothigh(prd, prd)
pl := pivotlow(prd, prd)

date = tostring(year) + "-" + tostring(month)

if (ph) //If 20 days ago was a pivot point
    label.new(bar_index-prd, ph, date, yloc=yloc.abovebar, color=color.green) //NOTE: bar_index-prd, becuse it occured 20 days ago
if (pl)
    label.new(bar_index-prd, pl, date, yloc=yloc.belowbar, color=color.red)