PINE LIBRARY
Zaktualizowano

Input Library [1CG]

474
Input Library (v1) – User Guide

Overview
The Input Library is a Pine Script® v6 utility library that standardizes and simplifies common user input patterns across indicators, strategies, and libraries.

It provides:
  • Predefined timezone enums mapped to IANA/Olson strings
  • 24-hour and 60-minute enumerations
  • Standardized line styles, sizes, label styles, and box alignment options
  • Helper methods for converting enums into TradingView constants
  • Utility functions for time formatting and span calculations


This library is designed to:
  • Reduce repetitive input boilerplate
  • Improve UI consistency across scripts
  • Prevent string-based input errors
  • Encourage clean, readable configuration logic



Library Declaration
To use the library in your script:

Pine Script®


Timezone Enums

Timezones
Provides a comprehensive list of IANA timezone identifiers using short, intuitive enum names.

Examples include:
  • utc → "UTC"
  • exch → Exchange timezone (syminfo.timezone)
  • ny → "America/New_York"
  • lon → "Europe/London"
  • tokyo → "Asia/Tokyo"
  • syd → "Australia/Sydney"


Method: timezoneToString()
Resolves the enum to a valid timezone string.

Pine Script®


Behavior:
  • If Timezones.exch is selected, returns syminfo.timezone
  • Otherwise returns the mapped IANA timezone string



Time Formatting Enums

hours
Represents 24-hour values from "00" through "23".

minutes
Represents minute values from "00" through "59".

Function: combineTime()
Combines hour and minute enums into a "HHMM" formatted string.

Pine Script®


Example output:
  • "0930"
  • "1600"



Drawing Style Enums

The library standardizes visual input options and converts them into TradingView constants.

LineStyle
  • solid
  • dotted
  • dashed
  • lArrow
  • rArrow
  • bArrow


Method: lineStyle()

Pine Script®



LineSize
  • thin → 1px
  • normal → 2px
  • heavy → 3px
  • thick → 4px
  • wide → 5px


Method: lineSize()

Pine Script®



TextSize
  • auto
  • tiny
  • small
  • normal
  • large
  • huge


Method: textSize()

Pine Script®



Box Alignment Enums

BoxHAlign
  • left
  • center
  • right


BoxVAlign
  • top
  • center
  • bottom


Methods:
Pine Script®



Line Extension

LineExtend
  • none
  • right
  • left
  • both


Method: lineExtend()

Pine Script®



Label Styles

LabelStyle
  • center
  • down
  • left
  • right
  • up
  • lowLeft
  • lowRight
  • upperLeft
  • upperRight


Method: labelStyle()

Pine Script®



String-Based Conversion Helpers

For compatibility with legacy scripts or string inputs:

  • lineStyleFromString()
  • lineSizeFromString()


These functions convert common string descriptions into valid TradingView constants.


Timezone Offset Utility

Function: getTZOffset()

Calculates the difference between a specified timezone and UTC.

Pine Script®


Returns:
  • Millisecond difference between UTC and the specified timezone
  • Accounts for daylight saving time



Time Span Utility

Function: timeSpan()

Converts common span names into milliseconds.

Supported values:
  • "Minute"
  • "Half Hour"
  • "Hour"
  • "4 Hours"
  • "8 Hours"
  • "12 Hours"
  • "Day"
  • "Week"


Example:
Pine Script®



Best Practices
  • Prefer enums over raw strings for safer configuration
  • Use conversion methods directly on enum inputs
  • Standardize visual settings across scripts using shared enums
  • Avoid hardcoding timezone strings where possible



Limitations
  • timeSpan() supports predefined span names only
  • getTZOffset() returns raw millisecond difference, not formatted hours
  • Library does not enforce input validation beyond enum constraints



Summary
The Input Library centralizes common input patterns into a reusable, structured framework. It improves script consistency, reduces UI friction, and ensures proper conversion between user selections and TradingView internal constants.

Designed for Pine Script® v6.
Informacje o Wersji
v2

Added:
method getOfficialTimezone(this)
  Converts the modified timezone enum back to its official name.
  Namespace types: series Timezones
  Parameters:
    this (series Timezones): (Timezones) The timezone enum value.
  Returns: (string) The official IANA timezone name without the offset brackets.
Informacje o Wersji
v3

Added:
textSizeFromString(_size)
  Parameters:
    _size (string)

boxHAlignFromString(_align)
  Parameters:
    _align (string)

boxVAlignFromString(_align)
  Parameters:
    _align (string)
Informacje o Wersji
v4

Added:
method toHHMMString(this)
  Converts a 15-minute enum selection into a compact HHMM string.
  Namespace types: series quarterHours
  Parameters:
    this (series quarterHours): (quarterHours) The quarter-hour enum value shown in the dropdown.
  Returns: (string) The compact time string. Example: "1430".

hhmmStringToParts(_hhmmString)
  Parameters:
    _hhmmString (string)

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.