PINE LIBRARY
Atualizado XZ_Core_Utilities

Library "XZ_Core_Utilities"
Generic formatting, identifier parsing and neutral geometry helpers for XZ scripts. Contains no XZ methodology or analytical authority.
csvContainsPositiveInt(objectId, csvIds)
Returns true when a positive integer ID occurs as a comma-separated token.
Parameters:
objectId (int): Positive integer to search for.
csvIds (string): Comma-separated integer text. Spaces are ignored.
Returns: True when objectId occurs as an exact parsed token.
csvFirstPositiveInt(csvIds)
Returns the first positive integer token in comma-separated text.
Parameters:
csvIds (string): Comma-separated integer text. Spaces are ignored.
Returns: First parsed positive integer, or 0 when none exists.
nearDuplicateBounds(lowA, highA, lowB, highB, tolerancePct)
Tests whether two low/high geometries are near-duplicates under a supplied percentage tolerance.
Parameters:
lowA (float): First lower bound.
highA (float): First upper bound.
lowB (float): Second lower bound.
highB (float): Second upper bound.
tolerancePct (float): Tolerance as a percentage of the wider geometry.
Returns: True when both corresponding boundaries fall within the calculated tolerance.
formatDate(eventTime, timezone)
Formats a timestamp as yyyy-MM-dd in the supplied timezone.
Parameters:
eventTime (int): UNIX timestamp in milliseconds.
timezone (string): Timezone string accepted by str.format_time().
Returns: Formatted date, or an em dash for na.
formatPercent(value)
Formats a percentage value with up to two decimals.
Parameters:
value (float): Percentage value.
Returns: Percentage text, or an em dash for na.
formatSignedPercent(value)
Formats a signed percentage value with up to two decimals.
Parameters:
value (float): Percentage value.
Returns: Signed percentage text, or an em dash for na.
timeframeLabel(tf)
Converts common TradingView timeframe strings into compact readable labels.
Parameters:
tf (string): TradingView timeframe string.
Returns: Compact label such as 1D, 1W, 4H or 15m.
formatDistance(distance, useTicks, minTick)
Formats an absolute price distance as points or ticks. Unit policy is supplied by the caller.
Parameters:
distance (float): Raw price distance.
useTicks (bool): True to convert distance to ticks.
minTick (float): Instrument minimum tick.
Returns: Formatted absolute distance with explicit unit.
directionalMovePct(fromPrice, toPrice, minTick)
Calculates signed percentage move from one price to another.
Parameters:
fromPrice (float): Chronological starting price.
toPrice (float): Chronological ending price.
minTick (float): Instrument minimum tick used to reject a near-zero denominator.
Returns: Signed percentage move, or na when unavailable.
normalizedPositionPct(currentValue, lowPrice, highPrice)
Calculates normalized position of a value within low-to-high geometry.
Parameters:
currentValue (float): Value being located.
lowPrice (float): Geometry lower bound.
highPrice (float): Geometry upper bound.
Returns: Position percentage where 0 is the lower bound and 100 is the upper bound. Values may fall outside 0-100.
formatElapsedDays(fromTime, toTime)
Formats elapsed milliseconds between two timestamps as fractional days.
Parameters:
fromTime (int): Starting timestamp.
toTime (int): Ending timestamp.
Returns: Day text with singular/plural unit, or an em dash when invalid.
quartilePrice(low, high, levelIndex)
Returns one of five equally spaced 0/25/50/75/100 geometry levels.
Parameters:
low (float): Lower geometry bound.
high (float): Upper geometry bound.
levelIndex (int): Integer level index from 0 to 4.
Returns: Price at the requested quartile level.
quartileText(levelIndex)
Returns the display text for quartile level index 0-4.
Parameters:
levelIndex (int): Integer level index from 0 to 4.
Returns: 0%, 25%, 50%, 75% or 100%.
appendUniqueToken(current, token, separator)
Appends a token only when it is not already present in a separator-delimited string.
Parameters:
current (string): Existing token string.
token (string): Token to append.
separator (string): Delimiter between tokens.
Returns: Original or extended token string.
Generic formatting, identifier parsing and neutral geometry helpers for XZ scripts. Contains no XZ methodology or analytical authority.
csvContainsPositiveInt(objectId, csvIds)
Returns true when a positive integer ID occurs as a comma-separated token.
Parameters:
objectId (int): Positive integer to search for.
csvIds (string): Comma-separated integer text. Spaces are ignored.
Returns: True when objectId occurs as an exact parsed token.
csvFirstPositiveInt(csvIds)
Returns the first positive integer token in comma-separated text.
Parameters:
csvIds (string): Comma-separated integer text. Spaces are ignored.
Returns: First parsed positive integer, or 0 when none exists.
nearDuplicateBounds(lowA, highA, lowB, highB, tolerancePct)
Tests whether two low/high geometries are near-duplicates under a supplied percentage tolerance.
Parameters:
lowA (float): First lower bound.
highA (float): First upper bound.
lowB (float): Second lower bound.
highB (float): Second upper bound.
tolerancePct (float): Tolerance as a percentage of the wider geometry.
Returns: True when both corresponding boundaries fall within the calculated tolerance.
formatDate(eventTime, timezone)
Formats a timestamp as yyyy-MM-dd in the supplied timezone.
Parameters:
eventTime (int): UNIX timestamp in milliseconds.
timezone (string): Timezone string accepted by str.format_time().
Returns: Formatted date, or an em dash for na.
formatPercent(value)
Formats a percentage value with up to two decimals.
Parameters:
value (float): Percentage value.
Returns: Percentage text, or an em dash for na.
formatSignedPercent(value)
Formats a signed percentage value with up to two decimals.
Parameters:
value (float): Percentage value.
Returns: Signed percentage text, or an em dash for na.
timeframeLabel(tf)
Converts common TradingView timeframe strings into compact readable labels.
Parameters:
tf (string): TradingView timeframe string.
Returns: Compact label such as 1D, 1W, 4H or 15m.
formatDistance(distance, useTicks, minTick)
Formats an absolute price distance as points or ticks. Unit policy is supplied by the caller.
Parameters:
distance (float): Raw price distance.
useTicks (bool): True to convert distance to ticks.
minTick (float): Instrument minimum tick.
Returns: Formatted absolute distance with explicit unit.
directionalMovePct(fromPrice, toPrice, minTick)
Calculates signed percentage move from one price to another.
Parameters:
fromPrice (float): Chronological starting price.
toPrice (float): Chronological ending price.
minTick (float): Instrument minimum tick used to reject a near-zero denominator.
Returns: Signed percentage move, or na when unavailable.
normalizedPositionPct(currentValue, lowPrice, highPrice)
Calculates normalized position of a value within low-to-high geometry.
Parameters:
currentValue (float): Value being located.
lowPrice (float): Geometry lower bound.
highPrice (float): Geometry upper bound.
Returns: Position percentage where 0 is the lower bound and 100 is the upper bound. Values may fall outside 0-100.
formatElapsedDays(fromTime, toTime)
Formats elapsed milliseconds between two timestamps as fractional days.
Parameters:
fromTime (int): Starting timestamp.
toTime (int): Ending timestamp.
Returns: Day text with singular/plural unit, or an em dash when invalid.
quartilePrice(low, high, levelIndex)
Returns one of five equally spaced 0/25/50/75/100 geometry levels.
Parameters:
low (float): Lower geometry bound.
high (float): Upper geometry bound.
levelIndex (int): Integer level index from 0 to 4.
Returns: Price at the requested quartile level.
quartileText(levelIndex)
Returns the display text for quartile level index 0-4.
Parameters:
levelIndex (int): Integer level index from 0 to 4.
Returns: 0%, 25%, 50%, 75% or 100%.
appendUniqueToken(current, token, separator)
Appends a token only when it is not already present in a separator-delimited string.
Parameters:
current (string): Existing token string.
token (string): Token to append.
separator (string): Delimiter between tokens.
Returns: Original or extended token string.
Notas de Lançamento
v2Added:
csvPositiveInts(csvIds)
Parses all positive integer tokens from comma-separated text.
Parameters:
csvIds (string): Comma-separated integer text. Spaces are ignored.
Returns: Array of positive integers in source order.
appendSeparatedText(base, item, separator)
Appends text using a separator only when the base is non-empty.
Parameters:
base (string)
item (string)
separator (string)
pushUniqueIntLimited(values, value, limit)
Pushes a non-negative integer only when absent and capacity remains.
Parameters:
values (array<int>)
value (int)
limit (int)
prioritizeUniqueIntLimited(values, value, limit)
Moves/inserts a non-negative integer to the front and enforces a maximum size.
Parameters:
values (array<int>)
value (int)
limit (int)
distanceUsesTicks(unitMode, instrumentType)
Resolves an Auto/Points/Ticks policy into a ticks boolean.
Parameters:
unitMode (string)
instrumentType (string)
positionRelationshipText(currentValue, lowPrice, highPrice, objectName)
Builds a generic normalized-position sentence for a bounded object.
Parameters:
currentValue (float)
lowPrice (float)
highPrice (float)
objectName (string)
Notas de Lançamento
v3Added:
dispatchAlertOncePerBarClose(message)
Dispatches a non-empty caller-built alert message once per bar close. The importing script remains authority for event existence, admission and message meaning.
Parameters:
message (string)
dispatchAlertOncePerBar(message)
Dispatches a non-empty caller-built alert message once per bar. The importing script remains authority for event existence, admission and message meaning.
Parameters:
message (string)
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.