PINE LIBRARY

Obj_XABCD_Harmonic

179
Library "Obj_XABCD_Harmonic"
Harmonic XABCD Pattern object and associated methods. Easily validate, draw, and get information about harmonic patterns. See example code at the end of the script for details.

init_params(pct_error, pct_asym, types, w_e, w_p, w_d)
  Create a harmonic parameters object (used by xabcd_harmonic object for pattern validation and scoring).
  Parameters:
    pct_error (float): Allowed % error of leg retracement ratio versus the defined harmonic ratio
    pct_asym (float): Allowed leg length/period asymmetry % (a leg is considered invalid if it is this % longer or shorter than the average length of the other legs)
    types (array<int>): Array of pattern types to validate (1=Gartley, 2=Bat, 3=Butterfly, 4=Crab, 5=Shark, 6=Cypher, 7=Alt-Bat, 8=Deep Butterfly, 9=Deep Crab)
    w_e (float): Weight of ratio % error (used in score calculation, dft = 1)
    w_p (float): Weight of PRZ confluence (used in score calculation, dft = 1)
    w_d (float): Weight of Point D / PRZ confluence (used in score calculation, dft = 1)
  Returns: harmonic_params object instance. It is recommended to store and reuse this object for multiple xabcd_harmonic objects rather than creating new params objects unnecessarily.

method erase_pattern(p)
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic)

init(x, a, b, c, d, params, tp, p)
  Initialize an xabcd_harmonic object instance from a given set of points
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
  Parameters:
    x (point type from reees/Pattern/1): Point X
    a (point type from reees/Pattern/1): Point A
    b (point type from reees/Pattern/1): Point B
    c (point type from reees/Pattern/1): Point C
    d (point type from reees/Pattern/1): Point D
    params (harmonic_params): harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
    tp (int): Pattern type
    p (xabcd_harmonic): xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
  Returns: xabcd_harmonic object instance if a valid harmonic, else na

init(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY, params, tp, p)
  Initialize an xabcd_harmonic object instance from a given set of x and y coordinate values.
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
  Parameters:
    xX (int): Point X bar index (required)
    xY (float): Point X price/level (required)
    aX (int): Point A bar index (required)
    aY (float): Point A price/level (required)
    bX (int): Point B bar index (required)
    bY (float): Point B price/level (required)
    cX (int): Point C bar index (required)
    cY (float): Point C price/level (required)
    dX (int): Point D bar index
    dY (float): Point D price/level
    params (harmonic_params): harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
    tp (int): Pattern type
    p (xabcd_harmonic): xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
  Returns: xabcd_harmonic object instance if a valid harmonic, else na

init(pattern, params, tp, p)
  Initialize an xabcd_harmonic object instance from a given pattern
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
  Parameters:
    pattern (pattern type from reees/Pattern/1): Pattern
    params (harmonic_params): harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
    tp (int): Pattern type
    p (xabcd_harmonic): xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
  Returns: xabcd_harmonic object instance if a valid harmonic, else na

method get_name(p)
  Get the pattern name
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: Pattern name (string)

method get_symbol(p)
  Get the pattern symbol from a pattern instance
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: Pattern symbol string

get_symbol(tp)
  Get the pattern symbol for a given pattern type integer.
Static overload — does not require a pattern instance.
  Parameters:
    tp (int): Pattern type (1=Gartley, 2=Bat, 3=Butterfly, 4=Crab, 5=Shark,
6=Cypher, 7=Alt-Bat, 8=Deep Butterfly, 9=Deep Crab)
  Returns: Pattern symbol string

method get_pid(p)
  Get the Pattern ID. Patterns of the same type with the same coordinates will have the same Pattern ID.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: Pattern ID (string)

method prz_range(p)
  Returns cached PRZ upper and lower bounds.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: [przUpper, przLower]

method incomplete_pid(p)
  Returns the pattern ID as if point D were unconfirmed (na).
Used to match incomplete patterns against their completed counterparts
during deduplication. Ensures pid format is consistent with the
library's internal pid generation.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: Pattern ID string with D forced to na

method set_target(p, target, target_lvl, calc_target)
  Set value for a target. Use the calc_target parameter to automatically calculate the target for a specific harmonic ratio.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
    target (int): Target (1 or 2)
    target_lvl (float): Target price/level (required if calc_target is not specified)
    calc_target (string): Target to auto calculate (required if target is not specified)
Options: [".382 AD", ".5 AD", ".618 AD", "1.272 AD", "1.618 AD"
".382 XA", ".5 XA" ,".618 XA", "1.272 XA", "1.618 XA",
".382 CD", ".5 CD", ".618 CD", "1.272 CD", "1.618 CD",
"A", "B", "C"]
  Returns: Target price/level (float)

method draw_pattern(p, clr)
  Draw the pattern
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
    clr (color)
  Returns: Pattern lines
[l1,l2,l3,l4,l5,l6]

method erase_label(p)
  Erase the pattern label
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: p

method draw_prz_levels(p, clr, extendBars)
  Draw PRZ target levels as horizontal dashed lines for incomplete patterns.
Shows where point D needs to land without implying a specific price path.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
    clr (color): Line color
    extendBars (int): Number of bars to extend the lines to the right (default 50)
  Returns: [nearLine, farLine] — the two PRZ level lines

method draw_label(p, clr, txt_clr, txt, tooltip)
  Draw the pattern label. Default text is the pattern name.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
    clr (color): Label color
    txt_clr (color): Text color
    txt (string): Label text
    tooltip (string): Tooltip text
  Returns: Label

method is_complete(p)
  Returns true if the pattern has a confirmed point D.
A pattern is complete when D exists AND is not an unconfirmed pivot.
Use this instead of checking na(p.d.x) directly — invalid_d being
false is a required condition that bare na checks miss.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
  Returns: bool

method age_pct(p, tLimitMult)
  Returns how far through the pattern's time limit it is, as a 0.0–1.0 float.
0.0 = just confirmed, 1.0 = time limit reached.
Returns na if pattern has no confirmed D point.
  Namespace types: xabcd_harmonic
  Parameters:
    p (xabcd_harmonic): Instance of xabcd_harmonic object
    tLimitMult (float): Pattern time limit multiplier (same value used in main script)
  Returns: float 0.0–1.0

harmonic_params
  Validation and scoring parameters for a Harmonic Pattern object (xabcd_harmonic)
  Fields:
    pct_error (series float): Allowed % error of leg retracement ratio versus the defined harmonic ratio
    pct_asym (series float)
    types (array<int>)
    w_e (series float)
    w_p (series float)
    w_d (series float)

xabcd_harmonic
  Harmonic Pattern object
  Fields:
    bull (series bool): Bullish pattern flag
    tp (series int)
    x (point type from reees/Pattern/1)
    a (point type from reees/Pattern/1)
    b (point type from reees/Pattern/1)
    c (point type from reees/Pattern/1)
    d (point type from reees/Pattern/1)
    r_xb (series float)
    re_xb (series float)
    r_ac (series float)
    re_ac (series float)
    r_bd (series float)
    re_bd (series float)
    r_xd (series float)
    re_xd (series float)
    score (series float)
    score_eAvg (series float)
    score_prz (series float)
    score_eD (series float)
    prz_bN (series float)
    prz_bF (series float)
    prz_xN (series float)
    prz_xF (series float)
    przUpper (series float)
    przLower (series float)
    t1Hit (series bool): Target 1 flag
    t1 (series float)
    t2Hit (series bool)
    t2 (series float)
    sHit (series bool): Stop flag
    stop (series float): Stop level
    entry (series float): Entry level
    eHit (series bool)
    e (point type from reees/Pattern/1)
    invalid_d (series bool)
    pLines (array<line>)
    pLabel (series label)
    cdLine (series line)
    pid (series string)
    params (harmonic_params)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.