PriceFormatLibrary for automatically converting price values to formatted strings
matching the same format that TradingView uses to display open/high/low/close prices on the chart.
█  OVERVIEW 
This library is intended for Pine Coders who are authors of scripts that display numbers onto a user's charts.  Typically, 𝚜𝚝𝚛.𝚝𝚘𝚜𝚝𝚛𝚒𝚗𝚐() would be used to convert a number into a string which can be displayed in a label / box / table, but this only works well for values that are formatted as a simple decimal number.  The purpose of this library is to provide an easy way to create a formatted string for values which use other types of formats besides the decimal format.
The main functions exported by this library are:
 
  𝚏𝚘𝚛𝚖𝚊𝚝𝙿𝚛𝚒𝚌𝚎() - creates a formatted string from a price value
  𝚖𝚎𝚊𝚜𝚞𝚛𝚎𝙿𝚛𝚒𝚌𝚎𝙲𝚑𝚊𝚗𝚐𝚎() - creates a formatted string from the distance between two prices
  𝚝𝚘𝚜𝚝𝚛𝚒𝚗𝚐() - an alternative to the built-in 𝚜𝚝𝚛.𝚝𝚘𝚜𝚝𝚛𝚒𝚗𝚐(𝚟𝚊𝚕𝚞𝚎, 𝚏𝚘𝚛𝚖𝚊𝚝)
 
This library also exports some auxiliary functions which are used under the hood of the previously mentioned functions, but can also be useful to Pine Coders that need fine-tuned control for customized formatting of numeric values:
 
  Functions that determine information about the current chart:
𝚒𝚜𝙵𝚛𝚊𝚌𝚝𝚒𝚘𝚗𝚊𝚕𝙵𝚘𝚛𝚖𝚊𝚝(), 𝚒𝚜𝚅𝚘𝚕𝚞𝚖𝚎𝙵𝚘𝚛𝚖𝚊𝚝(), 𝚒𝚜𝙿𝚎𝚛𝚌𝚎𝚗𝚝𝚊𝚐𝚎𝙵𝚘𝚛𝚖𝚊𝚝(), 𝚒𝚜𝙳𝚎𝚌𝚒𝚖𝚊𝚕𝙵𝚘𝚛𝚖𝚊𝚝(), 𝚒𝚜𝙿𝚒𝚙𝚜𝙵𝚘𝚛𝚖𝚊𝚝()
  Functions that convert a 𝚏𝚕𝚘𝚊𝚝 value to a formatted string:
𝚊𝚜𝙳𝚎𝚌𝚒𝚖𝚊𝚕(), 𝚊𝚜𝙿𝚒𝚙𝚜(), 𝚊𝚜𝙵𝚛𝚊𝚌𝚝𝚒𝚘𝚗𝚊𝚕(), 𝚊𝚜𝚅𝚘𝚕𝚞𝚖𝚎()
 
█  EXAMPLES 
•  Simple Example 
This example shows the simplest way to utilize this library.
  
//@version=6
indicator("Simple Example")
import n00btraders/PriceFormat/1
var table t = table.new(position.middle_right, 2, 1, bgcolor = color.new(color.blue, 90), force_overlay = true)
if barstate.isfirst
    table.cell(t, 0, 0, "Current Price: ", text_color = color.black, text_size = 40)
    table.cell(t, 1, 0, text_color = color.blue, text_size = 40)
if barstate.islast
    string lastPrice = close.formatPrice()      // Simple, easy way to format price
    table.cell_set_text(t, 1, 0, lastPrice)
 
•  Complex Example 
This example calls all of the main functions and uses their optional arguments.
  
//@version=6
indicator("Complex Example")
import n00btraders/PriceFormat/1
// Enum values that can be used as optional arguments
precision = input.enum(PriceFormat.Precision.DEFAULT)
language = input.enum(PriceFormat.Language.ENGLISH)
// Main library functions used to create formatted strings
string formattedOpen = open.formatPrice(precision, language, allowPips = true)
string rawOpenPrice = PriceFormat.tostring(open, format.price)
string formattedClose = close.formatPrice(precision, language, allowPips = true)
string rawClosePrice = PriceFormat.tostring(close, format.price)
  = PriceFormat.measurePriceChange(open, close, precision, language, allowPips = true)
// Labels to display formatted values on chart
string prices = str.format("Open:   {0}  ({1}) Close:   {2}  ({3})", formattedOpen, rawOpenPrice, formattedClose, rawClosePrice)
string change = str.format("Change (close - open): {0}   /   {1}", distance, ticks)
label.new(chart.point.now(high), prices, yloc = yloc.abovebar, textalign = text.align_left, force_overlay = true)
label.new(chart.point.now(low), change, yloc = yloc.belowbar, style = label.style_label_up, force_overlay = true)
 
█  NOTES 
•  Function Descriptions 
The library source code uses  Markdown  for the exported functions. Hover over a function/method call in the Pine Editor to display formatted, detailed information about the function/method.
  
•  Precision Settings 
The Precision option in the chart settings can change the format of how prices are displayed on the chart.  Since the user's selected choice cannot be known through any Pine built-in variable, this library provides a 𝙿𝚛𝚎𝚌𝚒𝚜𝚒𝚘𝚗 enum that can be used as an optional script input for the user to specify their selected choice.
  
•  Language Settings 
The Language option in the user menu can change the decimal/grouping separators in the prices that are displayed on the chart.  Since the user's selected choice cannot be known through any Pine built-in variable, this library provides a 𝙻𝚊𝚗𝚐𝚞𝚊𝚐𝚎 enum that can be used as an optional script input for the user to specify their selected choice.
  
█  EXPORTED FUNCTIONS 
 method formatPrice(price, precision, language, allowPips) 
  Formats a price value to match how it would be displayed on the user's current chart.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     price (float) : The value to format.
     precision (series Precision) : A Precision.* enum value.
     language (series Language) : A Language.* enum value.
     allowPips (simple bool) : Whether to allow decimal numbers to display as pips.
  Returns: Automatically formatted price string.
 measurePriceChange(startPrice, endPrice, precision, language, allowPips) 
  Measures a change in price in terms of both distance and ticks.
  Parameters:
     startPrice (float) : The starting price.
     endPrice (float) : The ending price.
     precision (series Precision) : A Precision.* enum value.
     language (series Language) : A Language.* enum value.
     allowPips (simple bool) : Whether to allow decimal numbers to display as pips.
  Returns: A tuple of formatted strings:  .
 method tostring(value, format) 
  Alternative to the Pine `str.tostring(value, format)` built-in function.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     value (float) : (series float) The value to format.
     format (string) : (series string) The format string.
  Returns: String in the specified format.
 isFractionalFormat() 
  Determines if the default behavior of the chart's price scale is to use a fractional format.
  Returns: True if the chart can display prices in fractional format.
 isVolumeFormat() 
  Determines if the default behavior of the chart's price scale is to display prices as volume.
  Returns: True if the chart can display prices as volume.
 isPercentageFormat() 
  Determines if the default behavior of the chart's price scale is to display percentages.
  Returns: True if the chart can display prices as percentages.
 isDecimalFormat() 
  Determines if the default behavior of the chart's price scale is to use a decimal format.
  Returns: True if the chart can display prices in decimal format.
 isPipsFormat() 
  Determines if the current symbol's prices can be displayed as pips.
  Returns: True if the chart can display prices as pips.
 method asDecimal(value, precision, minTick, decimalSeparator, groupingSeparator, eNotation) 
  Converts a number to a string in decimal format.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     value (float) : The value to format.
     precision (int) : Number of decimal places.
     minTick (float) : Minimum tick size.
     decimalSeparator (string) : The decimal separator.
     groupingSeparator (string) : The thousands separator, aka digit group separator.
     eNotation (bool) : Whether the result should use E notation.
  Returns: String in decimal format.
 method asPips(value, priceScale, minMove, minMove2, decimalSeparator, groupingSeparator) 
  Converts a number to a string in decimal format with the last digit replaced by a superscript.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     value (float) : The value to format.
     priceScale (int) : Price scale.
     minMove (int) : Min move.
     minMove2 (int) : Min move 2.
     decimalSeparator (string) : The decimal separator.
     groupingSeparator (string) : The thousands separator, aka digit group separator.
  Returns: String in decimal format with an emphasis on the pip value.
 method asFractional(value, priceScale, minMove, minMove2, fractionalSeparator1, fractionalSeparator2) 
  Converts a number to a string in fractional format.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     value (float) : The value to format.
     priceScale (int) : Price scale.
     minMove (int) : Min move.
     minMove2 (int) : Min move 2.
     fractionalSeparator1 (string) : The primary fractional separator.
     fractionalSeparator2 (string) : The secondary fractional separator.
  Returns: String in fractional format.
 method asVolume(value, precision, minTick, decimalSeparator, groupingSeparator, spacing) 
  Converts a number to a string in volume format.
  Namespace types: series float, simple float, input float, const float
  Parameters:
     value (float) : The value to format.
     precision (int) : Maximum number of decimal places.
     minTick (float) : Minimum tick size.
     decimalSeparator (string) : The decimal separator.
     groupingSeparator (string) : The thousands separator, aka digit group separator.
     spacing (string) : The whitespace separator.
  Returns: String in volume format.
Priceformatting
FvgPanel█ OVERVIEW 
This library provides functionalities for creating and managing a display panel within a Pine Script™ indicator. Its primary purpose is to offer a structured way to present Fair Value Gap (FVG) information, specifically the nearest bullish and bearish FVG levels across different timeframes (Current, MTF, HTF), directly on the chart. The library handles the table's structure, header initialization, and dynamic cell content updates.
 █ CONCEPTS 
The core of this library revolves around presenting summarized FVG data in a clear, tabular format. Key concepts include:
 FVG Data Aggregation and Display 
The panel is designed to show at-a-glance information about the closest active FVG mitigation levels. It doesn't calculate these FVGs itself but relies on the main script to provide this data. The panel is structured with columns for timeframes (TF), Bullish FVGs, and Bearish FVGs, and rows for "Current" (LTF), "MTF" (Medium Timeframe), and "HTF" (High Timeframe).
 The `panelData` User-Defined Type (UDT) 
To facilitate the transfer of information to be displayed, the library defines a UDT named `panelData`. This structure is central to the library's operation and is designed to hold all necessary values for populating the panel's data cells for each relevant FVG. Its fields include:
 
  Price levels for the nearest bullish and bearish FVGs for LTF, MTF, and HTF (e.g., `nearestBullMitLvl`, `nearestMtfBearMitLvl`).
  Boolean flags to indicate if these FVGs are classified as "Large Volume" (LV) (e.g., `isNearestBullLV`, `isNearestMtfBearLV`).
  Color information for the background and text of each data cell, allowing for conditional styling based on the FVG's status or proximity (e.g., `ltfBullBgColor`, `mtfBearTextColor`).
 
The design of `panelData` allows the main script to prepare all display-related data and styling cues in one object, which is then passed to the `updatePanel` function for rendering. This separation of data preparation and display logic keeps the library focused on its presentation task.
 Visual Cues and Formatting 
 
   Price Formatting:  Price levels are formatted to match the instrument's minimum tick size using an internal `formatPrice` helper function, ensuring consistent and accurate display.
   Large FVG Icon:  If an FVG is marked as a "Large Volume" FVG in the `panelData` object, a user-specified icon (e.g., an emoji) is prepended to its price level in the panel, providing an immediate visual distinction.
   Conditional Styling:  The background and text colors for each FVG level displayed in the panel can be individually controlled via the `panelData` object, enabling the main script to implement custom styling rules (e.g., highlighting the overall nearest FVG across all timeframes).
   Handling Missing Data:  If no FVG data is available for a particular cell (i.e., the corresponding level in `panelData` is `na`), the panel displays "---" and uses a specified background color for "Not Available" cells.
 
 █ CALCULATIONS AND USE 
Using the `FvgPanel` typically involves a two-stage process: initialization and dynamic updates.
 Step 1: Panel Creation 
First, an instance of the panel table is created once, usually during the script's initial setup. This is done using the `createPanel` function.
 
  Call `createPanel()` with parameters defining its position on the chart, border color, border width, header background color, header text color, and header text size.
  This function initializes the table with three columns ("TF", "Bull FVG", "Bear FVG") and three data rows labeled "Current", "MTF", and "HTF", plus a header row.
  Store the returned `table` object in a `var` variable to persist it across bars.
 
 
// Example:
var table infoPanel = na
if barstate.isfirst
    infoPanel := panel.createPanel(
         position.top_right,
         color.gray,
         1,
         color.new(color.gray, 50),
         color.white,
         size.small
       )
 
 Step 2: Panel Updates 
On each bar, or whenever the FVG data changes (typically on `barstate.islast` or `barstate.isrealtime` for efficiency), the panel's content needs to be refreshed. This is done using the `updatePanel` function.
 
  Populate an instance of the `panelData` UDT with the latest FVG information. This includes setting the nearest bullish/bearish mitigation levels for LTF, MTF, and HTF, their LV status, and their desired background and text colors.
  Call `updatePanel()`, passing the persistent `table` object (from Step 1), the populated `panelData` object, the icon string for LV FVGs, the default text color for FVG levels, the background color for "N/A" cells, and the general text size for the data cells.
  The `updatePanel` function will then clear previous data and fill the table cells with the new values and styles provided in the `panelData` object.
 
 
// Example (inside a conditional block like 'if barstate.islast'):
var panelData fvgDisplayData = panelData.new()
// ... (logic to populate fvgDisplayData fields) ...
// fvgDisplayData.nearestBullMitLvl = ...
// fvgDisplayData.ltfBullBgColor = ...
// ... etc.
if not na(infoPanel)
    panel.updatePanel(
         infoPanel,
         fvgDisplayData,
         "🔥", // LV FVG Icon
         color.white,
         color.new(color.gray, 70), // NA Cell Color
         size.small
       )
 
This workflow ensures that the panel is drawn only once and its cells are efficiently updated as new data becomes available.
 █ NOTES 
 
   Data Source:  This library is solely responsible for the visual presentation of FVG data in a table. It does  not  perform any FVG detection or calculation. The calling script must compute or retrieve the FVG levels, LV status, and desired styling to populate the `panelData` object.
   Styling Responsibility:  While `updatePanel` applies colors passed via the `panelData` object, the logic for *determining* those colors (e.g., highlighting the closest FVG to the current price) resides in the calling script.
   Performance:  The library uses `table.cell()` to update individual cells, which is generally more efficient than deleting and recreating the table on each update. However, the frequency of `updatePanel` calls should be managed by the main script (e.g., using `barstate.islast` or `barstate.isrealtime`) to avoid excessive processing on historical bars.
   `series float` Handling:  The price level fields within the `panelData` UDT (e.g., `nearestBullMitLvl`) can accept `series float` values, as these are typically derived from price data. The internal `formatPrice` function correctly handles `series float` for display.
   Dependencies:  The `FvgPanel` itself is self-contained and does not import other user libraries. It uses standard Pine Script™ table and string functionalities.
 
 █ EXPORTED TYPES 
 panelData 
  Represents the data structure for populating the FVG information panel. 
  Fields:
     nearestBullMitLvl (series float) : The price level of the nearest bullish FVG's mitigation point (bottom for bull) on the LTF. 
     isNearestBullLV (series bool) : True if the nearest bullish FVG on the LTF is a Large Volume FVG. 
     ltfBullBgColor (series color) : Background color for the LTF bullish FVG cell in the panel. 
     ltfBullTextColor (series color) : Text color for the LTF bullish FVG cell in the panel. 
     nearestBearMitLvl (series float) : The price level of the nearest bearish FVG's mitigation point (top for bear) on the LTF. 
     isNearestBearLV (series bool) : True if the nearest bearish FVG on the LTF is a Large Volume FVG. 
     ltfBearBgColor (series color) : Background color for the LTF bearish FVG cell in the panel. 
     ltfBearTextColor (series color) : Text color for the LTF bearish FVG cell in the panel. 
     nearestMtfBullMitLvl (series float) : The price level of the nearest bullish FVG's mitigation point on the MTF. 
     isNearestMtfBullLV (series bool) : True if the nearest bullish FVG on the MTF is a Large Volume FVG. 
     mtfBullBgColor (series color) : Background color for the MTF bullish FVG cell. 
     mtfBullTextColor (series color) : Text color for the MTF bullish FVG cell. 
     nearestMtfBearMitLvl (series float) : The price level of the nearest bearish FVG's mitigation point on the MTF. 
     isNearestMtfBearLV (series bool) : True if the nearest bearish FVG on the MTF is a Large Volume FVG. 
     mtfBearBgColor (series color) : Background color for the MTF bearish FVG cell. 
     mtfBearTextColor (series color) : Text color for the MTF bearish FVG cell. 
     nearestHtfBullMitLvl (series float) : The price level of the nearest bullish FVG's mitigation point on the HTF. 
     isNearestHtfBullLV (series bool) : True if the nearest bullish FVG on the HTF is a Large Volume FVG. 
     htfBullBgColor (series color) : Background color for the HTF bullish FVG cell. 
     htfBullTextColor (series color) : Text color for the HTF bullish FVG cell. 
     nearestHtfBearMitLvl (series float) : The price level of the nearest bearish FVG's mitigation point on the HTF. 
     isNearestHtfBearLV (series bool) : True if the nearest bearish FVG on the HTF is a Large Volume FVG. 
     htfBearBgColor (series color) : Background color for the HTF bearish FVG cell. 
     htfBearTextColor (series color) : Text color for the HTF bearish FVG cell. 
 █ EXPORTED FUNCTIONS 
 createPanel(position, borderColor, borderWidth, headerBgColor, headerTextColor, headerTextSize) 
  Creates and initializes the FVG information panel (table).  Sets up the header rows and timeframe labels. 
  Parameters:
     position (simple string) : The position of the panel on the chart (e.g., position.top_right).  Uses position.* constants. 
     borderColor (simple color) : The color of the panel's border. 
     borderWidth (simple int) : The width of the panel's border. 
     headerBgColor (simple color) : The background color for the header cells. 
     headerTextColor (simple color) : The text color for the header cells. 
     headerTextSize (simple string) : The text size for the header cells (e.g., size.small).  Uses size.* constants. 
  Returns: The newly created table object representing the panel. 
 updatePanel(panelTable, data, lvIcon, defaultTextColor, naCellColor, textSize) 
  Updates the content of the FVG information panel with the latest FVG data. 
  Parameters:
     panelTable (table) : The table object representing the panel to be updated. 
     data (panelData) : An object containing the FVG data to display. 
     lvIcon (simple string) : The icon (e.g., emoji) to display next to Large Volume FVGs. 
     defaultTextColor (simple color) : The default text color for FVG levels if not highlighted. 
     naCellColor (simple color) : The background color for cells where no FVG data is available ("---"). 
     textSize (simple string) : The text size for the FVG level data (e.g., size.small).
  Returns: _void

