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:
Pine Script®
2. Create a DisplayValue instance:
Pine Script®
3. Convert it to a string:
Pine Script®
4. Display the formatted string:
Pine Script®
Example
Pine Script®
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.
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.
ملاحظات الأخبار
v2Added:
percent(title, val)
Convenience constructor for percentage display values.
Parameters:
title (string)
val (float)
currency(title, val)
Convenience constructor for currency display values.
Parameters:
title (string)
val (float)
integer(title, val)
Convenience constructor for integer display values.
Parameters:
title (string)
val (float)
decimal(title, val)
Convenience constructor for decimal display values.
Parameters:
title (string)
val (float)
title(title)
Convenience constructor for title-only items.
Parameters:
title (string)
method set_value(this, val)
Sets the value from a boolean (1.0 for true, 0.0 for false).
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
val (bool)
method add(this, delta)
Adds a delta to the current value.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
delta (float)
method sub(this, delta)
Subtracts a delta from the current value.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
delta (float)
method mult(this, factor)
Multiplies the current value by a factor.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
factor (float)
method div(this, divisor)
Divides the current value by a divisor (safeguarded against divide-by-zero).
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
divisor (float)
method round(this, decimals)
Rounds the current value to a specified number of decimals.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
decimals (int)
method set_title(this, new_title)
Replaces the current title.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
new_title (string)
method append_title(this, suffix)
Appends a suffix to the existing title.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
suffix (string)
method prepend_title(this, prefix)
Prepends a prefix to the existing title.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
prefix (string)
method clear_title(this)
Clears the title.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
method set_format(this, new_format)
Updates the display format and recalculates the format string.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
new_format (series DisplayFormat)
method set_custom_format(this, custom_fmt)
Sets a custom format string (e.g., "{0}: [{1,number,#.000} USD]").
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
custom_fmt (string)
method hide(this)
Marks the item as hidden (producing an empty string when rendered).
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
method is_hidden(this)
Checks if the item is currently hidden.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
method tostring(this)
Alias for `to_string` matching standard conventions.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
method value_to_string(this)
Formats and returns only the numeric value portion (without title).
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
method to_strings(items)
Converts an array of DisplayValue items into an array of formatted strings.
Namespace types: array<DisplayValue>
Parameters:
items (array<DisplayValue>)
method join(items, separator)
Joins an array of DisplayValue items into a single formatted multi-line or separated string.
Namespace types: array<DisplayValue>
Parameters:
items (array<DisplayValue>)
separator (string)
Updated:
create(display_name, display_value, display_format)
Creates a new DisplayValue instance.
Parameters:
display_name (string): (string) Optional title label.
display_value (float): (float) Optional numeric value.
display_format (series DisplayFormat): (DisplayFormat) Optional format enum.
Returns: (DisplayValue) New instance.
method to_string(this)
Formats and renders the DisplayValue to a string.
Namespace types: DisplayValue
Parameters:
this (DisplayValue)
DisplayValue
Structure representing a display value.
Fields:
title (series string): (string) The title or label.
format_string (series string): (string) The format string used by str.format.
value (series float): (float) The numeric value to display.
format (series DisplayFormat): (DisplayFormat) The active format type.
ملاحظات الأخبار
v3-- hidden plots for speed compiling and added docs to source.
مكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
مكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.