XZ_Research_Utilities

Generic descriptive-statistics and two-column research-table utilities. Contains no XZ trading methodology or analytical authority.
resolvePosition(key)
Resolves a normalized table-position key.
Parameters:
key (string): Position key.
Returns: Pine table position constant.
resolveTextSize(key)
Resolves a normalized text-size key.
Parameters:
key (string): Size key.
Returns: Pine size constant.
countEqual(values, target)
Counts values equal to a target.
Parameters:
values (array<int>): Integer observations.
target (int): Target value.
Returns: Matching observation count.
countPositive(values)
Counts values greater than zero.
Parameters:
values (array<int>): Integer observations.
Returns: Positive observation count.
countAtLeast(values, threshold)
Counts values at or above a threshold.
Parameters:
values (array<int>): Integer observations.
threshold (int): Inclusive threshold.
Returns: Observation count at/above threshold.
sumInt(values)
Sums integer observations.
Parameters:
values (array<int>): Integer observations.
Returns: Sum.
selectedStat(values, mode)
Returns Median or Mean from float observations.
Parameters:
values (array<float>): Float observations.
mode (string): "Median" or "Mean".
Returns: Selected descriptive statistic or na for an empty sample.
number(value, suffix)
Formats a numeric result with an optional suffix.
Parameters:
value (float): Numeric result.
suffix (string): Suffix such as d or %.
Returns: Formatted number or em dash for na.
percent(numerator, denominator)
Formats numerator/denominator as a percentage.
Parameters:
numerator (int): Numerator.
denominator (int): Denominator.
Returns: Percentage or em dash when denominator is zero.
createTable(positionKey, rows, backgroundColor, lineColor, showLines)
Creates a two-column research table.
Parameters:
positionKey (string): Normalized table-position key.
rows (int): Row count.
backgroundColor (color): Background colour.
lineColor (color): Frame/border colour.
showLines (bool): Whether frame and borders are visible.
Returns: Table handle.
header(id, leftText, rightText, accentColor, textColor, backgroundColor, textSize, leftTooltip, rightTooltip)
Writes the two-column research header.
Parameters:
id (table): Table handle.
leftText (string): Left header text.
rightText (string): Right header text.
accentColor (color): Accent colour.
textColor (color): Neutral text colour.
backgroundColor (color): Shared background.
textSize (string): Normalized text-size key.
leftTooltip (string): Left-cell tooltip.
rightTooltip (string): Right-cell tooltip.
Returns: True after rendering.
row(id, row, labelText, valueText, textColor, accentColor, backgroundColor, textSize, tooltipText, accentValue)
Writes one label/value research row.
Parameters:
id (table): Table handle.
row (int): Row index.
labelText (string): Left label.
valueText (string): Right value.
textColor (color): Neutral text colour.
accentColor (color): Optional emphasized value colour.
backgroundColor (color): Shared background.
textSize (string): Normalized text-size key.
tooltipText (string): Shared metric-definition tooltip.
accentValue (bool): Whether the right value uses accent colour.
Returns: True after rendering.
Updated:
row(id, row, labelText, valueText, textColor, accentColor, backgroundColor, textSize, labelTooltip, valueTooltip, accentValue)
Writes one label/value research row with independent tooltip channels.
Parameters:
id (table): Table handle.
row (int): Row index.
labelText (string): Left label.
valueText (string): Right value.
textColor (color): Neutral text colour.
accentColor (color): Optional emphasized value colour.
backgroundColor (color): Shared background.
textSize (string): Normalized text-size key.
labelTooltip (string): Definition/decoder tooltip for the metric label.
valueTooltip (string): Optional value-specific tooltip. Pass an empty string when the displayed value is self-explanatory.
accentValue (bool): Whether the right value uses accent colour.
Returns: True after rendering.
Added:
rows(id, startRow, labels, values, tooltips, accents, textColor, accentColor, backgroundColor, textSize)
Renders a sequence of two-column research rows.
Parameters:
id (table)
startRow (int)
labels (array<string>)
values (array<string>)
tooltips (array<string>)
accents (array<bool>)
textColor (color)
accentColor (color)
backgroundColor (color)
textSize (string)
intArrayToFloat(values)
Converts an integer array to a float array preserving order.
Parameters:
values (array<int>)
Added:
pushFloatLimited(values, value, limit)
Appends one non-na float observation and trims the oldest observations to limit.
Parameters:
values (array<float>)
value (float)
limit (int)
mean(values)
Mean of float observations or na for an empty sample. Uses explicit summation for deterministic parity with existing XZ Research implementations.
Parameters:
values (array<float>)
median(values)
Median of float observations or na for an empty sample. Sorts a copy so caller order is preserved.
Parameters:
values (array<float>)
numberWithN(value, suffix, sampleN, nLabel)
Formats a numeric result with sample N.
Parameters:
value (float)
suffix (string)
sampleN (int)
nLabel (string)
selectedStatWithN(values, mode, suffix, nLabel)
Calculates selected Median/Mean and formats it with current sample N.
Parameters:
values (array<float>)
mode (string)
suffix (string)
nLabel (string)
scaledRate(numerator, denominator, scale)
Generic scaled rate. Returns na when denominator is not positive.
Parameters:
numerator (int)
denominator (int)
scale (float)
Updated:
countEqual(values, target)
Counts integer observations equal to target.
Parameters:
values (array<int>)
target (int)
countPositive(values)
Counts integer observations greater than zero.
Parameters:
values (array<int>)
countAtLeast(values, threshold)
Counts integer observations at or above an inclusive threshold.
Parameters:
values (array<int>)
threshold (int)
sumInt(values)
Sums integer observations.
Parameters:
values (array<int>)
selectedStat(values, mode)
Returns Median or Mean from float observations.
Parameters:
values (array<float>)
mode (string)
number(value, suffix)
Formats a numeric result with optional suffix; em dash for na.
Parameters:
value (float)
suffix (string)
percent(numerator, denominator)
Formats numerator/denominator as a percentage; em dash when denominator is zero.
Parameters:
numerator (int)
denominator (int)
Removed:
resolvePosition(key)
Resolves a normalized table-position key.
resolveTextSize(key)
Resolves a normalized text-size key.
createTable(positionKey, rows, backgroundColor, lineColor, showLines)
Creates a two-column research table.
header(id, leftText, rightText, accentColor, textColor, backgroundColor, textSize, leftTooltip, rightTooltip)
Writes the two-column research header.
row(id, row, labelText, valueText, textColor, accentColor, backgroundColor, textSize, labelTooltip, valueTooltip, accentValue)
Writes one label/value research row with independent tooltip channels.
rows(id, startRow, labels, values, tooltips, accents, textColor, accentColor, backgroundColor, textSize)
Renders a sequence of two-column research rows.
Added:
percentOr(numerator, denominator, emptyText)
Formats numerator/denominator as a percentage with caller-supplied empty text.
Parameters:
numerator (int)
denominator (int)
emptyText (string)
newCoverageState()
observeCoverage(state, observationTime)
Parameters:
state (CoverageState)
observationTime (int)
coverageCount(state)
Parameters:
state (CoverageState)
coverageFirstTime(state)
Parameters:
state (CoverageState)
coverageLastTime(state)
Parameters:
state (CoverageState)
coverageElapsedDays(state)
Parameters:
state (CoverageState)
newCategoryCountsState(categoryCount)
Parameters:
categoryCount (int)
incrementCategory(state, categoryIndex)
Parameters:
state (CategoryCountsState)
categoryIndex (int)
categoryCount(state, categoryIndex)
Parameters:
state (CategoryCountsState)
categoryIndex (int)
categoryTotal(state, fromIndex, toIndex)
Parameters:
state (CategoryCountsState)
fromIndex (int)
toIndex (int)
newBucketSetState(bucketCount)
Parameters:
bucketCount (int)
observeBucket(state, bucketIndex, directionCode, sampleValue, sampleLimit)
Parameters:
state (BucketSetState)
bucketIndex (int)
directionCode (int)
sampleValue (float)
sampleLimit (int)
bucketTotal(state, bucketIndex)
Parameters:
state (BucketSetState)
bucketIndex (int)
bucketPositive(state, bucketIndex)
Parameters:
state (BucketSetState)
bucketIndex (int)
bucketNegative(state, bucketIndex)
Parameters:
state (BucketSetState)
bucketIndex (int)
bucketSamples(state, bucketIndex)
Parameters:
state (BucketSetState)
bucketIndex (int)
newIntervalState()
overlap_count (series int)
Added:
newBinaryTransitionState()
armBinaryTransition(state, sourceBar, categoryIndex)
Parameters:
state (BinaryTransitionState)
sourceBar (int)
categoryIndex (int)
consumeBinaryTransition(state, destinationBar, sampleLimit, strictlyLater)
Parameters:
state (BinaryTransitionState)
destinationBar (int)
sampleLimit (int)
strictlyLater (bool)
binaryTransitionCount(state)
Parameters:
state (BinaryTransitionState)
binaryTransitionSamples(state)
Parameters:
state (BinaryTransitionState)
binaryTransitionCategoryCount(state, categoryIndex)
Parameters:
state (BinaryTransitionState)
categoryIndex (int)
binaryTransitionCategorySamples(state, categoryIndex)
Parameters:
state (BinaryTransitionState)
categoryIndex (int)
BinaryTransitionState
Fields:
pending_bar (series int)
pending_category (series int)
total_count (series int)
total_samples (array<float>)
category0_count (series int)
category1_count (series int)
category0_samples (array<float>)
category1_samples (array<float>)
Added:
numberOr(value, suffix, emptyText)
Parameters:
value (float)
suffix (string)
emptyText (string)
scaledRateText(numerator, denominator, scale, suffix, emptyText)
Parameters:
numerator (int)
denominator (int)
scale (float)
suffix (string)
emptyText (string)
coverageText(state, countSuffix, elapsedSuffix, emptyText)
Parameters:
state (CoverageState)
countSuffix (string)
elapsedSuffix (string)
emptyText (string)
categoryText7(state, label0, label1, label2, label3, label4, label5, label6)
Parameters:
state (CategoryCountsState)
label0 (string)
label1 (string)
label2 (string)
label3 (string)
label4 (string)
label5 (string)
label6 (string)
bucketDirectionText(state, bucketIndex, positiveLabel, negativeLabel)
Parameters:
state (BucketSetState)
bucketIndex (int)
positiveLabel (string)
negativeLabel (string)
episodeDirectionText(state, positiveLabel, negativeLabel)
Parameters:
state (EpisodeState)
positiveLabel (string)
negativeLabel (string)
geometryPairText(firstState, secondState, firstLabel, secondLabel)
Parameters:
firstState (GeometryState)
secondState (GeometryState)
firstLabel (string)
secondLabel (string)
geometryFourText(firstState, secondState, firstPositiveLabel, firstNegativeLabel, secondPositiveLabel, secondNegativeLabel)
Parameters:
firstState (GeometryState)
secondState (GeometryState)
firstPositiveLabel (string)
firstNegativeLabel (string)
secondPositiveLabel (string)
secondNegativeLabel (string)
maskCategorySummaryText(state, exactLabel, outsideLabel, overlapLabel, emptyPercentText)
Parameters:
state (MaskCategoryState)
exactLabel (string)
outsideLabel (string)
overlapLabel (string)
emptyPercentText (string)
maskCategorySingleAllText(state, memberIndex, memberLabel, outsideLabel)
Parameters:
state (MaskCategoryState)
memberIndex (int)
memberLabel (string)
outsideLabel (string)
maskCategorySingleText(state, categoryIndex, memberIndex, memberLabel)
Parameters:
state (MaskCategoryState)
categoryIndex (int)
memberIndex (int)
memberLabel (string)
maskCategoryCombinedSingleText(state, firstCategoryIndex, secondCategoryIndex, memberIndex, memberLabel)
Parameters:
state (MaskCategoryState)
firstCategoryIndex (int)
secondCategoryIndex (int)
memberIndex (int)
memberLabel (string)
maskCountSingleText(state, memberIndex, memberLabel, outsideLabel)
Parameters:
state (MaskCountState)
memberIndex (int)
memberLabel (string)
outsideLabel (string)
maskCategoryOriginRelationText(state, sameLabel, crossLabel, outsideLabel)
Parameters:
state (MaskCategoryState)
sameLabel (string)
crossLabel (string)
outsideLabel (string)
maskCategoryConsecutiveRelationText(state, sameLabel, crossLabel, outsideLabel)
Parameters:
state (MaskCategoryState)
sameLabel (string)
crossLabel (string)
outsideLabel (string)
maskCategoryAdaptiveAllText(state, useFourMembers, singleMemberIndex, singleLabel, outsideLabel, label0, label1, label2, label3)
Parameters:
state (MaskCategoryState)
useFourMembers (bool)
singleMemberIndex (int)
singleLabel (string)
outsideLabel (string)
label0 (string)
label1 (string)
label2 (string)
label3 (string)
maskCategoryAdaptiveText(state, categoryIndex, useFourMembers, singleMemberIndex, singleLabel, label0, label1, label2, label3)
Parameters:
state (MaskCategoryState)
categoryIndex (int)
useFourMembers (bool)
singleMemberIndex (int)
singleLabel (string)
label0 (string)
label1 (string)
label2 (string)
label3 (string)
maskCategoryAdaptiveCombinedText(state, firstCategoryIndex, secondCategoryIndex, useFourMembers, singleMemberIndex, singleLabel, label0, label1, label2, label3)
Parameters:
state (MaskCategoryState)
firstCategoryIndex (int)
secondCategoryIndex (int)
useFourMembers (bool)
singleMemberIndex (int)
singleLabel (string)
label0 (string)
label1 (string)
label2 (string)
label3 (string)
maskCountAdaptiveText(state, useFourMembers, singleMemberIndex, singleLabel, outsideLabel, label0, label1, label2, label3)
Parameters:
state (MaskCountState)
useFourMembers (bool)
singleMemberIndex (int)
singleLabel (string)
outsideLabel (string)
label0 (string)
label1 (string)
label2 (string)
label3 (string)
bucketRangeTotal(state, firstBucketIndex, lastBucketIndex)
Parameters:
state (BucketSetState)
firstBucketIndex (int)
lastBucketIndex (int)
geometryTotal(state)
Parameters:
state (GeometryState)
Perpustakaan pine
Dengan semangat TradingView yang sesungguhnya, penulis telah menerbitkan kode Pine ini sebagai pustaka sumber terbuka agar programmer Pine lain dari komunitas kami dapat menggunakannya kembali. Salut untuk penulis! Anda dapat menggunakan pustaka ini secara pribadi atau dalam publikasi sumber terbuka lainnya, tetapi penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib.
Pernyataan Penyangkalan
Perpustakaan pine
Dengan semangat TradingView yang sesungguhnya, penulis telah menerbitkan kode Pine ini sebagai pustaka sumber terbuka agar programmer Pine lain dari komunitas kami dapat menggunakannya kembali. Salut untuk penulis! Anda dapat menggunakan pustaka ini secara pribadi atau dalam publikasi sumber terbuka lainnya, tetapi penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib.