Pine Script Label Position

   The  xloc and yloc are two parameters (inputs) in label function. They tell how position values provided vide x,y (the other two parameters) are to be interpreted. Not to get confused , I summarise as :

1. x,y takes values for position of label

2. xloc and yloc can take input as constant. Example xloc can take values xloc.bar_index and xloc.bar_time, whereas yloc can take constant values as yloc.price, yloc,abovebar and yloc.belowbar. These xloc and yloc inform system on how to interpret data provided in x and y. Let say I provide a value as x=1089. Now, whether 1089 is on time axis or a bar number or price is not known to system. We provide this information vide xloc and yloc values.

The above will become more clear when we take examples.


In the above graph ( a 2-Dimensional Space), the location of any point can be represented in the form of  x, y. Let's say that the above is price of GOOG , then you can read from the graph that price is 410 and date is 16. Now , the confusion arises, whether the date is 16 or it is bar number. If xloc=xloc.bar_time is defined , then it is time and can be interpreted accordingly else if xloc=xloc.bar_time is defined, this 16 is the number of bar. 

In case of y, y is always price, however, if you are printing your label above or below bar , you can set yloc=yloc.abovebar or yloc=yloc=belowbar. In case you are using xloc=xloc.bar_time then you have to provide all time value in milliseconds. 

Summary

1. All x,y,xloc,yloc are parameters to label, other important parameters are text, color, style
2. If you don't define your xloc, then by default it is always xloc.bar_index
3. If you don't define your yloc, it is always yloc.price
4. If you don't define xloc and yloc, then 
label.new(x=bar_index, y=high,text="myLabel1") will print label on current bar at price = high.
5. If you set yloc=yloc.abovebar or yloc=yloc.belowbar then also you will have to provide x and y values.
6. I want to print a label one day before the current bar and I am using xloc=xloc.bar_time, then I can use x value as x=time - 86400000. Example is shown below:
label.new(x= time-86400000,y=high,xloc=xloc.bar_time,text="1")

Resources

Highest Rated Udemy Course on PineScript - Grab your Seat Now 

Udemy Discount Coupon Code : UDEMY-JAN23 (Valid upto 30th Nov 2023)

Learn more about coding on tradingview in PineScript through Books on pinescript available on amazon and kindle.


200+ pages book100 pages book200+ pages book


Point and Figure Charts : A Time-Tested Tool for Technical Analysis

In the dynamic world of financial markets, investors and traders constantly seek tools that can provide valuable insights into market trends...