Skip to content

teaceo-debug/DEEP6 / .claude/skills/tradingview-pinescript-error-doctor

tradingview-pinescript-error-doctor

Verified

errors/drawing-object-errors.md

View on GitHub
# Drawing Object Errors

Last verified: 2026-05-22

Use this file for labels, lines, boxes, and tables that crash, vanish, drift, or exceed limits.

## Failure Classes

### 1. Max count exceeded

Typical causes:

- no `max_labels_count`, `max_lines_count`, or `max_boxes_count` in `indicator()`
- object creation on every bar without reuse or deletion
- historical backfill creating hundreds of event markers

Mitigation:

```pine
indicator("Example", overlay = true, max_labels_count = 100, max_lines_count = 100, max_boxes_count = 50)
```

Counts only raise the ceiling. They do not solve uncontrolled creation.

### 2. Creating objects every bar without cleanup

Wrong:

```pine
label.new(bar_index, high, "X")
```

Safer singleton pattern:

```pine
var label statusLabel = na
if na(statusLabel)
    statusLabel := label.new(time, high, "Init", xloc = xloc.bar_time)
else
    label.set_x(statusLabel, time)
    label.set_y(statusLabel, high)
    label.set_text(statusLabel, "Live")
```

### 3. Calling setters on `na` IDs

Wrong:

```pine
line.set_y1(anchorLine, high)
```

Guard it:

```pine
if not na(anchorLine)
    line.set_y1(anchorLine, high)
```

### 4. `xloc.bar_index` vs `xloc.bar_time` confusion

- `xloc.bar_index`: anchors against integer bar positions; can drift visually after timeframe changes or resampling.
- `xloc.bar_time`: anchors against actual timestamps; better for candle-locked event markers and MTF-aware objects.

If an object must stay attached to a historical candle, prefer:

```pine
label.new(time, high, "Event", xloc = xloc.bar_time)
```

## Singleton `var` Pattern

Use for one dashboard label, one active box, one session line, or one table.

```pine
var box activeBox = na
if na(activeBox)
    activeBox := box.new(time, high, time, low, xloc = xloc.bar_time)
else
    box.set_left(activeBox, time)
    box.set_right(activeBox, time)
    box.set_top(activeBox, high)
    box.set_bottom(activeBox, low)
```

Without `var`, a new object ID is allocated every bar.

## Array-Based Cleanup Pattern For Event Objects

Use when you genuinely need many objects, but only a capped rolling set.

```pine
var array<label> eventLabels = array.new<label>()
maxEvents = 20

if eventSignal
    lbl = label.new(time, high, "Event", xloc = xloc.bar_time)
    array.push(eventLabels, lbl)

if array.size(eventLabels) > maxEvents
    old = array.shift(eventLabels)
    if not na(old)
        label.delete(old)
```

For conditional deletion across many elements, iterate in reverse when removing multiple items.

## Tables: Different Lifecycle Rules

Tables should almost always be singletons.

```pine
var table debugTable = table.new(position.top_right, 2, 3)
if barstate.islast
    table.cell(debugTable, 0, 0, "State")
    table.cell(debugTable, 1, 0, state)
```

Rules:

- declare with `var`
- create once
- update only on `barstate.islast` unless there is a very specific realtime need
- do not recreate the table every bar

## Fast Diagnosis

1. Check `indicator()` max object counts.
2. Search for `label.new`, `line.new`, `box.new`, `table.new` inside ungated bar logic.
3. Confirm every setter is guarded with `not na(id)`.
4. For candle-locked visuals, replace `bar_index` anchors with `time` + `xloc.bar_time`.
5. If many objects are intentional, add array caps and deletion.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 193kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 193kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 193kUpdated Claude CodeCodexVerifiedInstall