PINE LIBRARY
업데이트됨 PineDraw

Extracted from TheStrat Suite, where these components render six timeframes of levels on a single chart without running out of drawing objects. Nothing here knows anything about TheStrat, or about any strategy. It is the layer underneath: put an object at an exact price and time, keep it updated, and keep the chart readable when several of them land on the same price.
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.
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.
릴리즈 노트
ColoredLabelSet: price-merged labels where each row keeps its first entry's color and, optionally, its own time anchor, so labels can sit at their own line's end rather than in one column. Later entries at the same price append their text, and an entry whose text is already present on the row is skipped instead of repeated. Two draw styles: flushChips uses each row's color as the label background - the classic level-tag look - and flushText draws transparent colored text.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.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
Tools for traders and investors smart enough to keep it simple.
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
Tools for traders and investors smart enough to keep it simple.
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com
TheStrat Suite is now free & open source 😘👌 TheStratSuite.com
Build on it: github.com/natebking/345-strategies
Everything else: 345strategies.com
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.