Updated

ChartKit

305

More exclusive indicators from nilstrades_

Subscribe to Sir Pickle Indicators for $49.00/month to get exclusive indicators by this author. You pay right on TradingView and can use them on your charts straight away.

Explore Sir Pickle Indicators
Library "ChartKit"
Chart utilities: timeframe names and seconds, ticker checks, time and countdown texts, sending each alert line once, line styles from text, text boxes at the end of horizontal lines, merging the texts of line labels at the same price, label suffixes, outlined boxes and plain labels, boxes between two prices, keeping the newest labels, session checks for any timestamp, a per-bar drawing budget, and short settings codes (mixed radix, base 32, check character).

tfReadable(timeframeInSeconds)
  A timeframe's short name from its length in seconds: "30s", "5m", "4h", "D", "2D", "W", "M", "3M".
  Parameters:
    timeframeInSeconds (int): The timeframe's length, for example timeframe.in_seconds(timeframe.period).
  Returns: The name.

tfSeconds(name)
  The length in seconds of a timeframe named "15m", "1h", "4h", "D", "W" or "M".
  Parameters:
    name (simple string): One of these names.
  Returns: The seconds, as timeframe.in_seconds gives them.

tickerHas(parts)
  Does the chart's ticker contain one of these comma-separated parts?
  Parameters:
    parts (string): The parts, for example "AUD,JPY,NZD".
  Returns: true if syminfo.ticker contains at least one of them.

tickerStarts(parts)
  Does the chart's ticker start with one of these comma-separated parts?
  Parameters:
    parts (string): The parts, for example "BTC,ETH".
  Returns: true if syminfo.ticker starts with at least one of them.

fmtTime(t)
  A timestamp as "yyyy-MM-dd HH:mm" in New York time.
  Parameters:
    t (int): The timestamp.
  Returns: The text, "-" if t is na.

countdown(left)
  A duration as "mm:ss", or as "hh:mm:ss" from one hour on; a time already past counts as 0 (with delayed data a bar's close can lie in the past).
  Parameters:
    left (int): The duration in milliseconds, for example time_close - timenow.
  Returns: The text.

sameTime(last, t)
  Are both timestamps set and equal? For example: is this the candle that was already handled (last)?
  Parameters:
    last (int): The remembered timestamp (na: none yet).
    t (int): The timestamp to check.
  Returns: true if neither is na and they are equal.

newLines(msgs, sent)
  The lines of msgs that sent doesn't contain yet, for sending each alert line only once (the script keeps sent, for example in a varip variable that it clears on every new bar). Empty lines are skipped.
  Parameters:
    msgs (string): The lines to send, separated by "\n".
    sent (string): The lines sent so far, each followed by "\n".
  Returns: [the new lines joined with "\n" ("" if there are none), sent with the new lines added].

lineStyle(s)
  A line style from its name.
  Parameters:
    s (string): "dotted", "dashed" or anything else (solid).
  Returns: line.style_dotted, line.style_dashed or line.style_solid.

lineText(left, right, y, txt, below, textColor, size)
  A text right-aligned to the end of a horizontal line: an invisible box of no height from left to right at y.
  Parameters:
    left (int): Bar time where the box starts.
    right (int): Bar time where the text ends.
    y (float): The line's price.
    txt (string): The text.
    below (bool): true: the text sits below the line, false: above it.
    textColor (color): The text color.
    size (simple int): The text size.
  Returns: The box.

labelLeft(x, y, txt, textColor, size)
  A left-aligned label without background at bar time x.
  Parameters:
    x (int): Bar time.
    y (float): Price.
    txt (string): The text.
    textColor (color): The text color.
    size (simple int): The text size.
  Returns: The label.

setSuffix(lb, sep, tag)
  Replaces the end of a label's text: cuts it at the first sep (if any) and appends tag.
  Parameters:
    lb (label): The label.
    sep (string): Where the end starts, for example " · ".
    tag (string): The new end, usually starting with sep ("" removes the end).

capLabels(a, n)
  Deletes the oldest labels until at most n are left.
  Parameters:
    a (array<label>): The labels, oldest first.
    n (int): How many to keep.

priceBox(x, a, b, c)
  A filled box without border between two prices, of zero width at bar time x (widen it with box.set_right).
  Parameters:
    x (int): Bar time.
    a (float): One price.
    b (float): The other price.
    c (color): The fill color.
  Returns: The box.

setPrices(bx, a, b)
  Moves a box's top and bottom to two prices.
  Parameters:
    bx (box): The box.
    a (float): One price.
    b (float): The other price.

outlineBox(left, top, right, bottom, txt, valign, halign)
  A box with a gray outline and gray text (size 10) and no fill, from bar time left to right.
  Parameters:
    left (int): Bar time where the box starts.
    top (float): The box's top.
    right (int): Bar time where the box ends.
    bottom (float): The box's bottom.
    txt (string): The text.
    valign (string): The text's vertical alignment (text.align_top, text.align_center or text.align_bottom).
    halign (string): The text's horizontal alignment.
  Returns: The box.

textLabel(x, y, txt, style, c)
  A label without background at bar time x, text size 10.
  Parameters:
    x (int): Bar time.
    y (float): Price.
    txt (string): The text.
    style (string): The label style, for example label.style_label_up.
    c (color): The text color.
  Returns: The label.

addLbl(all, lb, sec, below, txt)
  Collects a line's text box for mergeLbls and clears its text (the merge writes it back). It goes after the boxes with a higher or equal order key, so higher keys come first in a merged text.
  Parameters:
    all (array<LineLbl>): The collection.
    lb (box): The text box (na: nothing to collect).
    sec (int): Its order key.
    below (bool): The text sits below its line.
    txt (string): The text.

mergeLbls(all, gap)
  Texts at the same price, on the same side and at most gap ms apart are shown once each, joined with " + ", in the rightmost box of the group; the other boxes stay empty.
  Parameters:
    all (array<LineLbl>): The collected boxes (addLbl).
    gap (int): The largest distance in milliseconds between two boxes of a group.

trimGroups(bs, ls, lbs, counts, nb, nl, nlb, keep)
  Drawings grouped per bar: records this bar's new boxes, lines and labels (the array sizes before were nb, nl and nlb) and deletes the drawings of the oldest bars beyond keep bars.
  Parameters:
    bs (array<box>): The boxes, oldest first.
    ls (array<line>): The lines, oldest first.
    lbs (array<label>): The labels, oldest first.
    counts (array<int>): How many of each every recorded bar added (three numbers per bar).
    nb (int): The size of bs before this bar's drawings.
    nl (int): The size of ls before this bar's drawings.
    nlb (int): The size of lbs before this bar's drawings.
    keep (int): How many bars with drawings to keep.

sessMinutes(sess, pos)
  Minutes after midnight of the "HHMM" at position pos of a session string.
  Parameters:
    sess (string): A session such as "0930-1600".
    pos (int): 0 for the start, 5 for the end.

inSession(t, sess)
  Is time t inside session "HHMM-HHMM" (New York time)? A session across midnight wraps.
  Parameters:
    t (int): A timestamp.
    sess (string): The session.

opt(v, opts)
  The position of v among "|"-separated options, 0 if it is none of them.
  Parameters:
    v (string): The value.
    opts (string): The options, for example "off|1R|2R".

bits(a)
  Switches as one number, one binary digit each (the first switch is the highest digit).
  Parameters:
    a (array<bool>): The switches.

pack(v, r, len)
  Values as one mixed-radix number, written as len base-32 digits (no 0, O, I or L).
  Parameters:
    v (array<int>): The values, each from 0 to its number of options minus one.
    r (array<int>): Each value's number of options.
    len (int): The number of digits.

check(c)
  A check character: the base-32 digits weighted by their place.
  Parameters:
    c (string): The digits.

code(raw)
  A 14-digit code as "XXXXX-XXXXX-XXXX" followed by its check character.
  Parameters:
    raw (string): The 14 digits.

LineLbl
  A line text box collected for merging.
  Fields:
    lb (series box): The text box.
    y (series float): Its price.
    x (series int): Its right edge (bar time).
    below (series bool): Text below the line.
    txt (series string): Its text.
    sec (series int): Its order key (higher first).
    used (series bool): Merged into an earlier one.
Release Notes
v2
- New: lowerTf() gives the finer and the coarser lower timeframe whose candles fit inside a chart candle, for request.security_lower_tf().
- New: the Intrabars type and intrabars(): a candle's lower-timeframe candles with its high and low; sequence() and afterCross() tell what price reached first inside the candle.
- New: filled() and rebuilds() check that lower-timeframe candles exist and add up to the chart candle's high and low.
- New: firstBeyond(), firstNear(), firstRecord(), earlier() and pick(): find the first value beyond or at a level, or a new high or low, compare two events' order, and combine two readings.
- New: drawCandle() draws a candle as a box and two wick lines; clearDrawings() deletes the boxes, lines and labels in lists and empties them.
- New: swap() exchanges two lists' contents; fingerprint() gives a short checksum of a text.
- The existing functions are unchanged.
Release Notes
v3
- New: barBox() and barLevel() draw a one-bar box with a text and a one-bar level with a label.
- New: timeLevel() draws a line between two bar times with a label at its end and keeps only the newest ones.
- New: tintBox() draws a tinted box with an outline; hLine() draws a horizontal line between two bar times.
- New: the TradeBoxes type, tradeBoxes() and its methods draw a trade: boxes from the entry to the stop and to the target, a breakeven line and lines where the stop moved.
- New: the RangeDraw type and its methods delete, extend, move, color and mark a range's box, label, lines and their texts.
- The existing functions are unchanged.
Release Notes
v4
- New: writeCode() writes a script's settings as one short code from a layout (groups of base-32 digits, each a mixed-radix number of fields, some groups only when needed, a check character); readCode() reads such a code back into the SettingsCode type.
- New: codeDiff() names the fields in which two codes of the same layout differ.
- New: check31() gives a check character over base-32 digits; groups() writes a text in groups of characters.
- New: whole() gives a value as a whole number when it is one; unbits() turns a number made by bits() back into its switches.
- New: tfSecondsOf() gives the length of a timeframe named "15m" to "M" for a name that can change from bar to bar.
- New: codeText() writes a code's settings out in words, from its layout and a name for each field.
- New: beyondDir(), shortOfDir() and atOrShortOfDir() compare two prices in a direction; beyond() compares them up or down; choose() picks one of three switches by position.
- New: addTo() adds an item to a list written as text; h4Name() writes the timeframe "240" as "4h"; nyTime() gives the time a New York session starts or ends on the current bar's day.
- The existing functions are unchanged.

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.