PINE LIBRARY

display_value

OVERVIEW

This script is a tinny library for creating and displaying formatted values in TradingView scripts. It provides a structured way to present key information like titles, percentages, currency values, decimals, and integers with clear formatting. This allows you to coordinate your strings in advance and hold one item to use for calling your string to a label, box, table.. Made for day to day use of most typical use cases, more advanced techniques should be used for complicated scenarios.

Building Blocks

User Defined Types (UDTs)

The script defines a UDT called `DisplayValue` to encapsulate the components of a display value:

 * title: The title or label of the value.
 * format_string: The string used to format the value (e.g., "{0} -     1,number,percent}").
 * value: The actual value to be displayed.
 * format: An enum value specifying the desired format (percent, currency, etc.).

Enums

The `DisplayFormat` enum provides predefined constants for various formatting options, making the code more readable and less prone to errors.

Functions

 * create(): This function creates a new `DisplayValue` instance. It takes the title, value, and desired format as arguments and generates the appropriate format string.
 * to_string(): This function converts a `DisplayValue` instance into a formatted string ready for display on the chart.



How to Use

1. Import the library:

2. Create a DisplayValue instance:

3. Convert it to a string:

4. Display the formatted string:




Example



This will display a label on the chart with the text "Profit - 15%".

### Notes

* The library handles the formatting details, making it easier to display values consistently in your scripts.
* The use of enums and UDTs improves code organization and readability.




--------



Library "display_value"

create(display_name, display_value, display_format)
  Gets the appropriate format string based on the display format.
  Parameters:
    display_name (string): (string) The name of the display value. Default is na.
    display_value (float)
    display_format (series DisplayFormat)
  Returns: (DisplayValue) A new DisplayValue instance with the formatted value.

to_string(item)
  Converts the display value to a string with the specified format.
  Parameters:
    item (DisplayValue): (DisplayValue) The display value to convert to a string.
  Returns: (string) The string representation of the display value.

DisplayValue
  Structure representing a display value.
  Fields:
    title (series string): (string) The title of the display value.
    format_string (series string): (string) The format string to use for display.
    value (series float): (float) The value to display.
    format (series DisplayFormat): (DisplayFormat) The format to use.


displayformatting

파인 라이브러리

진정한 TradingView 정신에 따라, 저자는 이 파인 코드를 다른 파인 프로그래머들이 재사용할 수 있도록 오픈 소스 라이브러리로 공개했습니다. 저자에게 박수를 보냅니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈 소스 출판물에서 사용할 수 있지만, 이 코드를 출판물에서 재사용하는 것은 하우스 룰에 의해 관리됩니다.

면책사항