PineDraw

The script ends with a small demo that marks the prior bar's high and low, so you can add the library to a chart and see the primitives run before importing anything.
Library "PineDraw"
Object primitives for indicators that draw price levels: update lines,
boxes and labels in place instead of deleting and recreating them every tick, pool
labels so a busy chart stays under the object limit, and merge labels that land on the
same price so they read as one row instead of overlapping.
updateLine(ref, x1, y1, x2, y2, col, w, style)
Update a line in place, or create it if the reference is na.
Parameters:
ref (line): Existing line, or na on the first call.
x1 (int): Left anchor, in bar time (ms).
y1 (float): Left price.
x2 (int): Right anchor, in bar time (ms).
y2 (float): Right price.
col (color): Line color.
w (int): Line width.
style (string): One of line.style_solid, line.style_dashed, line.style_dotted.
Returns: The line reference. Assign it back: `myLine := updateLine(myLine, ...)`.
updateBox(ref, x1, y1, x2, y2, bg, border)
Update a box in place, or create it if the reference is na.
Parameters:
ref (box): Existing box, or na on the first call.
x1 (int): Left anchor in bar time (ms).
y1 (float): Top price.
x2 (int): Right anchor in bar time (ms).
y2 (float): Bottom price.
bg (color): Fill color.
border (color): Border color.
Returns: The box reference.
clearLine(ref)
Delete a line if it exists. Assign the result back to clear your reference.
Parameters:
ref (line): Line to remove, or na.
Returns: na, typed as a line.
clearBox(ref)
Delete a box if it exists. Assign the result back to clear your reference.
Parameters:
ref (box): Box to remove, or na.
Returns: na, typed as a box.
newPool()
Create an empty pool. Assign to a `var` so it survives across bars.
Returns: A new LabelPool.
method reset(this)
Start a render pass. Hides any label left over from the previous pass.
Namespace types: LabelPool
Parameters:
this (LabelPool): The pool.
Returns: The pool, for chaining.
method acquire(this, x, y, txt, useBarIndex, bg, txtCol, sz)
Take the next label from the pool, creating one only if the pool is exhausted.
Namespace types: LabelPool
Parameters:
this (LabelPool): The pool.
x (int): Anchor, bar time in ms when useBarIndex is false, otherwise a bar index.
y (float): Price.
txt (string): Label text.
useBarIndex (bool): Anchor to bar_index instead of bar time. Use for labels that should
float at a fixed offset from the current bar rather than sit at a point in history.
bg (color): Background color.
txtCol (color): Text color.
sz (string): One of size.tiny, size.small, size.normal, size.large.
Returns: The label, already positioned and styled.
newSet()
Create an empty label set for one render pass.
Returns: A new LabelSet.
method add(this, price, txt, joiner, tolerance)
Add a label at a price, merging into an existing row if one is close enough.
Namespace types: LabelSet
Parameters:
this (LabelSet): The set.
price (float): The price to label.
txt (string): The text to add.
joiner (string): Placed between merged entries, for example " + ".
tolerance (float): How far apart two prices can be and still share a row, in price units.
Pass 0 to merge only exact ticks. syminfo.mintick is a sane floor; a fraction of
ta.atr() adapts across instruments.
Returns: The set, for chaining.
method flush(this, pool, x, useBarIndex, bg, txtCol, sz)
Draw a consolidated set through a pool, in one call.
Namespace types: LabelSet
Parameters:
this (LabelSet): The set to draw.
pool (LabelPool): The label pool to draw through.
x (int): Anchor for every label in the set.
useBarIndex (bool): Anchor to bar_index instead of bar time.
bg (color): Background color.
txtCol (color): Text color.
sz (string): Text size.
Returns: The number of labels drawn.
lineStyle(style)
Map a style name to a Pine line style constant.
Parameters:
style (string): "Solid", "Dashed" or "Dotted". Anything else returns dotted.
Returns: A line.style_* constant.
textSize(name)
Map a size name to a Pine size constant.
Parameters:
name (string): "Tiny", "Small", "Normal" or "Large". Anything else returns small.
Returns: A size.* constant.
LabelPool
A reusable set of labels. Hold one in a `var` at the top of your script.
Fields:
items (array<label>): Every label ever allocated by this pool.
used (series int): How many have been handed out in the current render pass.
LabelSet
A set of labels-to-be, grouped by price.
Fields:
prices (array<float>): One entry per distinct price.
texts (array<string>): The merged text for each price.
LabelPool.trim(): ends a render pass by deleting every pooled label beyond the ones acquired, so switching a feature off removes its labels instead of leaving blanks against the object cap. reset, acquire, trim is the recommended pass.
tablePos(): maps a position name from an input dropdown to the table position constant.
Библиотека Pine
В истинном духе TradingView автор опубликовал этот код Pine как библиотеку с открытым исходным кодом, чтобы другие программисты Pine из нашего сообщества могли её использовать. Браво автору! Вы можете использовать эту библиотеку для личного пользования или в других публикациях с открытым исходным кодом, но повторное использование этого кода в публикациях регулируется Правилами поведения.
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com
Отказ от ответственности
Библиотека Pine
В истинном духе TradingView автор опубликовал этот код Pine как библиотеку с открытым исходным кодом, чтобы другие программисты Pine из нашего сообщества могли её использовать. Браво автору! Вы можете использовать эту библиотеку для личного пользования или в других публикациях с открытым исходным кодом, но повторное использование этого кода в публикациях регулируется Правилами поведения.
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com