AddLabel ( boolean visible , Any text , CustomColor color , int location , int size , boolean rowOwnership );
Default values:
color: Color.RED
location: Location.TOP_LEFT
size: FontSize.SMALL
rowOwnership: no
Description
Adds a text label to the specified location on the chart. Note that you can also use this function to display some text in custom quotes (see example below).
You can use the optional rowOwnership
parameter to make a label claim exclusive use of the row it is placed on. This is helpful when displaying important messages or banners that shouldn’t be crowded by other labels. When a label has rowOwnership = yes
, no other label can appear in the same row, even if it shares the same location or font size. Other labels will be pushed to adjacent rows.
Note: When AddLabel()
calls another function, e.g., AddLabel(yes, "GetDividend: " + GetDividend());
-- it only uses the value of that function at the last real bar. So in this example, if the last real bar does not contain any dividend announcement, the value will be N/A.
Tip: To avoid label overlap with chart elements like bubbles or bars, you can enable the Fit study markers option. Go to Chart settings, then Price axis, and check Fit study markers.
Input parameters
Parameter | Default value | Description |
---|---|---|
visible | - | Defines the condition upon which the label is displayed. |
text | - | Defines the text to be displayed in the label. |
color | Color.RED | Defines the color of the label. You can use a Color constant for this parameter. |
location | Location.TOP_LEFT | Defines the location of the label. You can use a Location constant for this parameter. |
size | FontSize.SMALL | Defines the font size of the label. You can use a FontSize constant for this parameter. |
rowOwnership |
no |
If set to |
Example
def avgPrice = GetAveragePrice();
def trendUp = close > Average(close);
AddLabel(yes, "My Avg Price: " + avgPrice, if trendUp then Color.GREEN else Color.RED, location = Location.TOP_LEFT, size = FontSize.SMALL, rowOwnership = yes);
AddLabel(yes, if close > Average(close, 20) then "Uptrend" else "Downtrend", location = Location.TOP_RIGHT, size = FontSize.X_LARGE);
The first label shows My Avg Price: [value]
in green or red depending on whether the current price is above or below the average close. This label uses the rowOwnership = yes
parameter, which causes it to claim the entire row for itself. No other label can appear on the same row.
The second label displays "Uptrend" or "Downtrend" based on a 20-bar moving average. Because the first label owns its row, this label is automatically pushed to the next row below, even though both are set to the same location. If used in Custom Quotes, the words "Uptrend" or "Downtrend" will appear in the quote cell based on the same condition.