Sidechair

box.copy()

Browse the reference

Draws a second box with the same edges, fill, outline, extension and text as an existing one, and returns it.

Try it in the editor

The twin sits exactly on top of the original until you move it, so copy first and then change an edge or a color. Later edits to either box leave the other alone.

Edges, colors, border settings, extend mode, xloc and text all carry over. The copy counts toward max_boxes_count like any new box, so copying at the cap removes the oldest box.

Syntax

Pine Script
box.copy(id: series box) -> series box
box.copy() -> series box

Arguments

NameTypeDefaultDescription
idseries boxrequiredThe box to duplicate. It is only read; the original keeps every setting it had.

Returns

series box: The new box, painted above the original, or na when id is na.

Remarks

  • On Sidechair: copying na, or a value that is not a box, returns na instead of stopping the script.

Example

Pine ScriptMirror a zone further rightOpen in editor
//@version=6
indicator("box.copy: repeated zone", overlay = true)
if barstate.islast
    zone = box.new(bar_index - 20, high, bar_index - 10, low, bgcolor = color.new(color.blue, 85))
    twin = box.copy(zone)
    box.set_left(twin, bar_index - 9)
    box.set_right(twin, bar_index)

See also

Runs on Sidechair