TEProfile PeaksShelvesVisits SessionFold

293
Library "TEProfile_PeaksShelvesVisits_SessionFold"
Market-profile and fitting maths for Pine arrays: a volume profile's point of control and high-volume rows, time-at-price shelves, visits to a price band and how each ended, an ordinary least-squares fit with a band side and a fit-window picker, a Wilder ATR over arrays, a CME Globex session fold with the prior trading day's value area, a log(1 + k) table and small array helpers. No trading rules.

pushTagged(cP, cT, cL, price, ty, lb)
  appends one tagged price to three parallel arrays: the price, its type code and its label code. Nothing is appended when the price is na.
  Parameters:
    cP (array<float>): output: the price is pushed here
    cT (array<int>): output: the type code is pushed here
    cL (array<int>): output: the label code is pushed here
    price (float): the price (na appends nothing)
    ty (int): the type code
    lb (int): the label code
  Returns: true

weightsOrDefault(w, dflt)
  a copy of a weight array in which every na or zero weight is replaced by a default
  Parameters:
    w (array<float>): the weights
    dflt (float): the value written in place of an na or zero weight
  Returns: a new array, the same length as w

ringPushPair(ps, bs, p, b, keep)
  pushes one value onto each of two parallel rings and, when the first ring is longer than keep, shifts the oldest value off both. Keep the two rings the same length: only the first one's size is checked.
  Parameters:
    ps (array<float>): the first ring (oldest first), updated in place
    bs (array<int>): the second ring, updated in place in lockstep
    p (float): the value pushed onto ps
    b (int): the value pushed onto bs
    keep (int): the most values a ring holds
  Returns: the size of ps after the push

log1pTable()
  ln(1 + k) for k = 0 … 79 as the 80 IEEE-754 doubles JavaScript's Math.log1p returns; math.log(1 + k) differs from them at k = 13 in the last bit, so a script that must match a JavaScript reference bit for bit reads this table
  Returns: a new array of 80 floats, index k holding ln(1 + k)

profilePeaksInto(h, l, v, bins, cP, cT, cL, tick, pocTy, pocLb, hvnTy, hvnLb)
  writes a volume profile's point of control and its high-volume rows into three parallel output arrays. Rows are max(1, ceil((highest high − lowest low) / bins / tick)) ticks tall, filled by TE Math's profileRows (each bar's volume spread per tick of its range). The point of control (the first row holding the most volume) is written first, then every other inner row whose volume is at least both neighbours' and at least 0.55 × the point of control's, each at its row's centre. The row height uses the whole of h and l (their highest high and lowest low), even where v is shorter. Nothing is written for fewer than 10 bars, fewer than 3 bins or 3 rows, no volume, or tick ≤ 0.
  Parameters:
    h (array<float>): highs
    l (array<float>): lows
    v (array<float>): volumes (the profile covers the shortest of the three)
    bins (int): the number of rows the range is divided into, before rounding the row height up to whole ticks
    cP (array<float>): output: prices are pushed here
    cT (array<int>): output: type codes are pushed here
    cL (array<int>): output: label codes are pushed here
    tick (float): the tick size the rows are built on (nothing is written when tick ≤ 0)
    pocTy (int): the type code written with the point of control
    pocLb (int): the label code written with the point of control
    hvnTy (int): the type code written with each high-volume row
    hvnLb (int): the label code written with each high-volume row
  Returns: true

shelvesInto(h, l, bins, minShare, cP, cT, cL, ty, lb)
  writes time-at-price shelves into three parallel output arrays. The range from the lowest low to the highest high is split into `bins` equal bins; each bar adds 1, spread evenly over the bins its low-to-high range touches. Each inner bin (not the first or the last) whose count is at least minShare of the total and at least both neighbours' counts is written at its centre. Nothing is written for fewer than 20 bars, fewer than 3 bins or a flat range.
  Parameters:
    h (array<float>): highs
    l (array<float>): lows (the count covers the shorter of h and l)
    bins (int): the number of bins
    minShare (float): the smallest share of the total count a bin must hold (0 to 1)
    cP (array<float>): output: prices are pushed here
    cT (array<int>): output: type codes are pushed here
    cL (array<int>): output: label codes are pushed here
    ty (int): the type code written with each shelf
    lb (int): the label code written with each shelf
  Returns: true

visitCounts(h, l, c, ts, price, tol, orient, from)
  counts the visits of a bar series to a price band and how each ended. A visit is a run of bars whose range reaches price ± tol; it counts when its first bar starts at or after `from`. A counted visit is judged once, when it ends (the next bar lies wholly outside the band): a close on the holding side is held, otherwise broke. The holding side is orient when it is not 0 (+1: a close above the band holds, −1: a close below it holds), else the side the visit came from (the last close outside the band before it; unknown: neither). A visit still open at the last bar is counted but not judged.
  Parameters:
    h (array<float>): highs, oldest first
    l (array<float>): lows, oldest first
    c (array<float>): closes, oldest first
    ts (array<int>): each bar's start time, oldest first (the walk covers the shortest of the four arrays)
    price (float): the price at the centre of the band
    tol (float): the band half-width
    orient (int): +1, −1, or 0 for the side the visit came from
    from (int): the earliest start time a counted visit may begin at
  Returns: a tuple [visits counted, held, broke]

linearFit(c, fromI, toI)
  ordinary least squares of c on x = i over the indexes fromI … toI, so the fitted value at index i is a + b × i; sigma is the root of the mean squared residual. All three are na unless 0 ≤ fromI, toI < size(c) and the window holds at least 3 values.
  Parameters:
    c (array<float>): the values
    fromI (int): the first index of the window
    toI (int): the last index of the window (inclusive)
  Returns: a tuple [a, b, sigma]

bandSide(lastC, center, sigma, dev)
  which side of a band around a centre a value lies on: +1 above centre + dev × sigma, −1 below centre − dev × sigma, 0 between them or when any input is na
  Parameters:
    lastC (float): the value to place (for example the last close)
    center (float): the band centre
    sigma (float): the band unit (for example a residual standard deviation)
    dev (float): the band half-width in units of sigma
  Returns: +1, −1 or 0

windowFromLastPivot(nowBar, hiBars, loBars, minLen, maxLen)
  the first index of a window ending at nowBar that starts at the newest pivot index at or before nowBar (taken from either array; na entries are ignored), or nowBar − maxLen + 1 when there is none, then clamped so the window is at least minLen and at most maxLen values long
  Parameters:
    nowBar (int): the last index of the window
    hiBars (array<int>): the indexes of the pivot highs
    loBars (array<int>): the indexes of the pivot lows
    minLen (int): the shortest window
    maxLen (int): the longest window
  Returns: the first index of the window

atrOrZero(h, l, c, period)
  Wilder's average true range of `period` (TE Math's Atr) folded over three arrays, oldest first; 0.0 while it is still na (fewer than `period` true ranges)
  Parameters:
    h (array<float>): highs, oldest first
    l (array<float>): lows, oldest first
    c (array<float>): closes, oldest first (the fold covers the shortest of the three)
    period (int): the ATR length
  Returns: the ATR, or 0.0

sessionFoldNew(atrLen)
  a new, empty session fold: no session yet, a Wilder ATR of atrLen for the finished sessions, and empty bar and daily-row arrays
  Parameters:
    atrLen (int): the length of the sessions' ATR (sAtr)
  Returns: a SessionFold

sessionFoldStep(d, t, h, l, c, v, tick)
  folds one COMPLETED bar into the CME Globex session that holds it (TE Math's trade date and its 17:00 New York close). When a new trade date starts it closes the previous one: appends it to sesK / sesH / sesL as a daily row (high and low, or na when fewer than 1,242 bars were folded) unless its date is at or before seedK, folds its high − low into sAtr, and sets pvOk, poc, vah and val to its 70% value area (TE Math, rows of 0.02 × sAtr) when it is the trading day before the new one and was folded from within 30 minutes of its 18:00 open to within 30 minutes of its close for at least 90% of its minutes, with sAtr warm. Call it once per bar, oldest first.
  Parameters:
    d (SessionFold): the fold state, updated in place
    t (int): the bar's time
    h (float): the bar's high
    l (float): the bar's low
    c (float): the bar's close
    v (float): the bar's volume
    tick (float): the tick size the value area rows are built on
  Returns: the session's bar count after this bar (the fold itself is in d)

SessionFold
  the state of a CME session fold. Create it with sessionFoldNew and step it with sessionFoldStep.
  Fields:
    key (series int): the trade date (yyyymmdd) being folded; na before the first bar
    kEnd (series int): the close time of the session being folded
    kNow (series int): the trade date of the latest bar
    first (series int): the time of the first bar folded into this session
    lastT (series int): the time of the last bar folded into this session
    n (series int): how many bars this session has folded
    sH (series float): this session's high so far
    sL (series float): this session's low so far
    sAtr (Atr type from TradersEdgeUSA/TEMath_WilderSuperTrend_TickGridValueArea/1): the Wilder ATR of the finished sessions' high − low (sessionFoldNew sets its length)
    pH (array<float>): this session's bar highs
    pL (array<float>): this session's bar lows
    pC (array<float>): this session's bar closes
    pV (array<float>): this session's bar volumes
    pvOk (series bool): whether poc, vah and val describe the session that finished last
    poc (series float): its point of control
    vah (series float): its value area high
    val (series float): its value area low
    sesK (array<int>): the daily rows' trade dates
    seedK (series int): the last trade date the caller appended to the daily rows itself; a finished session at or before it is not appended (na for none)
    sesH (array<float>): the daily rows' highs, na for a session folded for fewer than 1,242 bars
    sesL (array<float>): the daily rows' lows, na alongside sesH

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。