PINE LIBRARY

TheStrat Grammar: Objective Bar State Definitions and Notation

432
Library "TheStratGrammar"
Classification primitives for TheStrat: reduce any candle to the
four-field state every notation projects from (structure, above-open, failed, live),
then render it either as chart notation (2u, F2d, 1u - the u/d overload traders know)
or as glyph notation (2u<, F2d>, 1>) where the token never carries sign and > / <
carry close-versus-open exclusively. Includes hammer/shooter proportion patterns and
Full Timeframe Continuity. Definitions only: nothing here decides what to trade.

aboveOpen(o, c)
  The sign channel: did a candle close above its own open?
  Parameters:
    o (float): Open.
    c (float): Close.
  Returns: true only for a strictly higher close. A doji buckets down.

structureOf(prevH, prevL, h, l)
  Classify a candle against the prior candle's range.
Equal is not a break: a high exactly matching the prior high has not crossed it.
Gaps get no special case - classification tests the range, never the open, so a
gap-up open above the prior high is already at least a 2u.
  Parameters:
    prevH (float): Prior candle high.
    prevL (float): Prior candle low.
    h (float): Current candle high.
    l (float): Current candle low.
  Returns: "1", "2u", "2d" or "3". Empty string on invalid input (na, or high below low).

isFailed(prevH, prevL, o, c, structure, method)
  Did a directional break get rejected? Only 2u/2d can fail: an inside bar
broke nothing and an outside bar broke both sides, so neither has one break to reject.
  Parameters:
    prevH (float): Prior candle high.
    prevL (float): Prior candle low.
    o (float): Current candle open.
    c (float): Current candle close.
    structure (string): The structure from structureOf().
    method (string): "Reclaim", "Open", "Reclaim + Open" or "Reclaim OR Open" - the same option strings TheStrat Suite exposes, so an indicator can pass its input through. Reclaim: closed back inside the prior range. Open: closed against the break direction.
  Returns: true when the break was rejected under the chosen method.

classify(prevH, prevL, o, h, l, c, method, live)
  Reduce a candle to its BarState in one call.
  Parameters:
    prevH (float): Prior candle high.
    prevL (float): Prior candle low.
    o (float): Current open.
    h (float): Current high.
    l (float): Current low.
    c (float): Current close.
    method (string): Failed-break method, as in isFailed(). Pass "Reclaim" if unsure.
    live (bool): Is the candle still forming.
  Returns: A BarState, or na when the inputs do not classify.

method notation(this)
  Chart-convention token: 1u, 2d, F2u, 3d. The u/d overload lives here, at
the display boundary, and nowhere else.
  Namespace types: BarState
  Parameters:
    this (BarState): The state.
  Returns: The token, for example "F2u" or "1d". Empty string for na.

signGlyph(above)
  The sign glyph: ">" when the close is above the open, "<" otherwise.
  Parameters:
    above (bool): The aboveOpen flag.
  Returns: ">" or "<".

method display(this)
  Glyph-convention token: structure with no sign, then > or <. A red 2u is
"2u<" - break side and sign visibly separate. Matches priceactionapi's display field.
  Namespace types: BarState
  Parameters:
    this (BarState): The state.
  Returns: For example "F2u<", "1>", "3<". Empty string for na.

combo(tokens, sep, potential)
  Join state tokens into a combo, oldest to newest. The last token is the
forming candle - position is what carries liveness, which is why notation is
tense-free.
  Parameters:
    tokens (array<string>): Tokens oldest to newest, from notation() or display().
    sep (string): Separator, usually "-" or "".
    potential (bool): Prefix with "*" for a setup that has not triggered.
  Returns: The combo string, for example "*2d-1-2u".

isHammer(o, h, l, c, method, requireColor)
  A candle that rejected its low.
  Parameters:
    o (float): Open.
    h (float): High.
    l (float): Low.
    c (float): Close.
    method (string): "Broad (Loose)", "Classic" or "Pin Bar (Strict)" - TheStrat Suite's option strings. Broad: open and close both strictly above the midpoint (a body centered exactly at the midpoint is neither pattern). Classic: small body, long rejection wick. Pin Bar: body confined to the top quarter.
    requireColor (bool): Additionally require a close above the open.
  Returns: true when the candle qualifies.

isShooter(o, h, l, c, method, requireColor)
  A candle that rejected its high. Mirror of isHammer.
  Parameters:
    o (float): Open.
    h (float): High.
    l (float): Low.
    c (float): Close.
    method (string): As in isHammer.
    requireColor (bool): Additionally require a close below the open.
  Returns: true when the candle qualifies.

continuity(signs)
  Read continuity across timeframes, from the sign channel only. Do not
reconstruct this from structure tokens: a 2u can close red. Pass the aboveOpen of
each monitored timeframe's current candle, all sampled at the same moment.
  Parameters:
    signs (array<bool>): One aboveOpen per monitored timeframe.
  Returns: "Up" when every sign is true, "Down" when every sign is false, else "Conflict". An empty array is "Conflict".

BarState
  The four-field state every notation projects from.
  Fields:
    structure (series string): "1", "2u", "2d" or "3" - what this candle did to the prior range. The u/d here is the BREAK SIDE, never the sign.
    aboveOpen (series bool): Close strictly above open. A close at the open is not above; it buckets down.
    failed (series bool): A directional break got rejected. Only 2u/2d can fail.
    live (series bool): The candle is still forming.

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.