PINE LIBRARY

Kerbal_Helpers

49
Library "kerbal_helpers"
Kerbal Indicators Shared Library - Drawing object helpers
This library provides utilities for managing labels, boxes, and areas within Pine Script limits (500 each).
Includes deduplication, cleanup, filtering, and zone management functions.

ageFilter(barIndex, creationBar, maxAge)
  Check if an object is too old based on bar index
  Parameters:
    barIndex (int): Current bar index
    creationBar (int): Bar index when object was created
    maxAge (int): Maximum age in bars
  Returns: True if object should be filtered out (too old)

distanceFilter(price, referencePrice, atrMultiplier, atr)
  Check if price is within acceptable distance from reference
  Parameters:
    price (float): The price to check
    referencePrice (float): The reference price
    atrMultiplier (float): ATR multiplier for distance
    atr (float): The ATR value
  Returns: True if within acceptable distance

weightFilter(weight, minWeight)
  Check if weight meets minimum threshold
  Parameters:
    weight (float): The weight value
    minWeight (float): Minimum acceptable weight
  Returns: True if weight is acceptable

perfectionFilter(isPerfected, requirePerfection)
  Check perfection requirement (for Price Exhaustion clusters)
  Parameters:
    isPerfected (bool): Whether the signal is perfected
    requirePerfection (bool): Whether perfection is required
  Returns: True if passes perfection filter

boxOverlaps(box1Top, box1Bot, box2Top, box2Bot)
  Check if two boxes overlap in price space
  Parameters:
    box1Top (float): Top price of first box
    box1Bot (float): Bottom price of first box
    box2Top (float): Top price of second box
    box2Bot (float): Bottom price of second box
  Returns: True if boxes overlap

boxMerge(box1Top, box1Bot, box2Top, box2Bot)
  Calculate the merged boundaries of two overlapping boxes
  Parameters:
    box1Top (float): Top price of first box
    box1Bot (float): Bottom price of first box
    box2Top (float): Top price of second box
    box2Bot (float): Bottom price of second box
  Returns: Tuple [mergedTop, mergedBot]

priceInZone(price, boxTop, boxBot)
  Check if a price is within a box/zone
  Parameters:
    price (float): The price to check
    boxTop (float): Top of the box
    boxBot (float): Bottom of the box
  Returns: True if price is within box boundaries

zoneCenter(boxTop, boxBot)
  Calculate the center price of a zone
  Parameters:
    boxTop (float): Top of the zone
    boxBot (float): Bottom of the zone
  Returns: Center price

zoneWidth(boxTop, boxBot)
  Calculate zone width/thickness
  Parameters:
    boxTop (float): Top of the zone
    boxBot (float): Bottom of the zone
  Returns: Zone width

labelsNearby(x1, y1, x2, y2, barTolerance, priceTolerance)
  Check if two labels would be too close (for deduplication)
  Parameters:
    x1 (int): Bar index of first label
    y1 (float): Price of first label
    x2 (int): Bar index of second label
    y2 (float): Price of second label
    barTolerance (int): Maximum bar distance for considering labels duplicate
    priceTolerance (float): Maximum price distance for considering labels duplicate
  Returns: True if labels are close enough to be considered duplicates

labelDistance(x1, y1, x2, y2, atr)
  Calculate distance score between two label positions (lower is closer)
  Parameters:
    x1 (int): Bar index of first label
    y1 (float): Price of first label
    x2 (int): Bar index of second label
    y2 (float): Price of second label
    atr (float): ATR value for price normalization
  Returns: Distance score (0+ range, lower means closer)

clusterType(hasSession, hasPivot, hasVolume, weight, goldThreshold, limeThreshold)
  Classify cluster composition based on anchor types present
  Parameters:
    hasSession (bool): Whether cluster contains session anchors (daily/weekly)
    hasPivot (bool): Whether cluster contains pivot anchors
    hasVolume (bool): Whether cluster contains volume anchors
    weight (float): Total cluster weight
    goldThreshold (float): Weight threshold for "gold" classification
    limeThreshold (float): Weight threshold for "lime" classification
  Returns: Cluster type: "GOLD", "LIME", "MIXED", "SESSION", "PIVOT", "VOLUME"

clusterColor(clusterType)
  Get color for cluster based on type
  Parameters:
    clusterType (string): The cluster type string
  Returns: Appropriate color for the cluster type

zoneSignificant(weight, width, minWeight, maxWidth)
  Check if a zone is significant enough to display
  Parameters:
    weight (float): Zone weight
    width (float): Zone width in price
    minWeight (float): Minimum weight threshold
    maxWidth (float): Maximum width threshold (ATR-based)
  Returns: True if zone should be displayed

mergeZones(prices, widths, tolerance)
  Merge multiple nearby zones into a single wider zone
  Parameters:
    prices (array<float>): Array of zone center prices
    widths (array<float>): Array of zone widths
    tolerance (float): Merging tolerance (typically ATR-based)
  Returns: Tuple of [mergedCenters, mergedWidths] arrays

findSupportResistance(prices, currentPrice)
  Calculate support and resistance levels from an array of prices
  Parameters:
    prices (array<float>): Array of price levels
    currentPrice (float): Current market price
  Returns: Tuple of [nearestSupport, nearestResistance]

zoneStrength(weight, age, touches, width, maxAge, maxTouches, optimalWidth)
  Calculate zone strength score based on multiple factors
  Parameters:
    weight (float): Zone weight (volume participation)
    age (int): Bars since zone creation
    touches (int): Number of price touches/tests
    width (float): Zone width
    maxAge (int): Maximum age for full score
    maxTouches (int): Maximum touches for full score
    optimalWidth (float): Optimal zone width (narrower is better)
  Returns: Strength score 0-100

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.