The example’s label uses either yloc.belowbar or yloc.abovebar y-locations, which don’t require a y value.Ī finite value for y is needed only if a label uses yloc.price. One may notice that na is passed as the y argument to the label.new function call. Text, color, y coordinate location ( yloc) and label style. Then, depending on whether the current bar is rising or falling (condition close >= open), a number of label drawing properties are modified: This simple script first creates a label on the current bar and then it writes a reference to it in a variable l. For study ( "My Script", overlay = true ) l = label.new ( bar_index, na ) if close >= open t_text ( l, "green" ) t_color ( l, een ) t_yloc ( l, yloc.belowbar ) t_style ( l, label.style_label_up ) else t_text ( l, "red" ) t_color ( l, color.red ) t_yloc ( l, yloc.abovebar ) t_style ( l, label.style_label_down ) The xloc.bar_time and xloc.bar_index modes makes it possible to place a drawing object in the future, to the right of the current bar. Time can also be set to an absolute time point with the The bar time of previous bars is time, time and so on. The start time of the current bar can be obtained from the built-in variable time. The x-coordinate is treated as a UNIX time in milliseconds. If a drawing object uses xloc.bar_time, then xloc.bar_index is the default value for x-location parameters of both label and line drawings. The bar index of previous bars is bar_index, bar_index and so on. The bar index of the current bar can be obtained from the built-in variable bar_index. The x-coordinate is treated as an absolute bar index. If a drawing object uses xloc.bar_index, then y is ignored when yloc is set to yloc.abovebar or yloc.belowbar.
The value of xloc determines whether x will hold a bar index or time value. Drawing objects are positioned on the chart according to x and y coordinates using a combination of 4 parameters: x, y, xloc and yloc.