Fxxtrader
Pine Script Rookie
Pine Script Rookie
Posts: 22
Joined: September 6th, 2020
Location: Toronto
Contact: Twitter TradingView Profile

Watermark Label

Hello Coders, hope you're doing well. With some help from Pine Script chat room, I started this watermark label.

From the chat room, I don't understand what these lines mean?

Code: Select all

 f_print(_text) => var _label

And this line:

Code: Select all

f_print(syminfo.ticker + "\n" + timeframe.period)

I understand inside the bracket, but what is f_print doing?

Eventually, I'd like to make the text more dynamic.

Here is the full script:

Code: Select all

//@version=4

study("Watermark Label", shorttitle="Watermark", overlay=true)

// Input
showWaterMrk    = input(title="Show WaterMark Details", type=input.bool, defval=true)

//  Watermark Label
wtrmrk_YLoc      = input(title="Watermark Y Location", type=input.float, defval=2.0, step=0.25)
wtrmrk_XLoc      = input(title="Watermark X Location", type=input.integer, defval=-8)
bar_Duration    = time - time[1]
offset          = wtrmrk_XLoc * bar_Duration
highest         = highest(high, 13) + (atr(14)) * wtrmrk_YLoc
labelCol        = close[1]>open[1] ? color.green : color.red
textCol         = close[1]>open[1] ?color.white : color.lime

//  Label - label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip)

f_print(_text) => var _label = label.new(time, y=na, text=_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.white, style=label.style_label_center,
 textcolor=color.black, size=size.large, textalign=text.align_center),
 label.set_xy(_label, time + offset, highest),
 label.set_text(_label, _text),
 label.set_color(_label, labelCol),
 label.set_textcolor(_label, textCol)
f_print(syminfo.ticker + "\n" + timeframe.period)
// End of Watermark

Thank you.

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: Watermark Label

Hi Fxxtrader

The f_print(_text) => line is a custom function that just creates a label. It's kind of hard to read when it's all on one line. Below is what it looks like if you break it into multiple lines.

Code: Select all

f_print(_text) => 
	var _label = label.new(
	  time, y=na,
	  text=_text,
	  xloc=xloc.bar_time,
	  yloc=yloc.price,
	  color=color.white,
	  style=label.style_label_center,
	  textcolor=color.black, 
	  size=size.large, 
	  textalign=text.align_center) 
This line is using the custom f_print function to create a label to display the ticker name and timeframe on the chart:
f_print(syminfo.ticker + "\n" + timeframe.period)

Hope that helps.

Return to “Pine Script Q&A”