pine-script

draw rectangle pine script


I would like draw a rectangle box over specific candles range using pine script, can anyone please help me on this ?

like below pic:

enter image description here


Solution

  • You have line 4 with every argument used, you have to know the sides (left, top, right, bottom) for your square, everything else is for design.

    //@version=4
    study("My Script", overlay=true)
    
    // box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor)
    b = box.new(bar_index[100], highest(high,50), bar_index[10], lowest(low, 50), color.purple, 1, line.style_solid, extend.none, xloc.bar_index, color.new(color.purple, 90))
    box.delete(b[1])
    

    enter image description here

    Also you can read the docs here.