Search code examples
pine-scriptpine-script-v4

How to draw a rectangle in pinescript v4


I tried to create a rectangle using this code in pinescript v.4:

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])

but getting error:

The 'resolution' argument is incompatible with functions that have side effects.

Solution

  • The resolution argument of the study() function is not compatible with the functions with side effects - drawings, alert() function calls etc.

    In Pine Script v5, the resolution= parameter has been renamed timeframe= and this aspect is explicitly highlighted in the manual:

    timeframe (const string) Adds multi-timeframe functionality to simple scripts. When used, a "Timeframe" field will be added to the script's "Settings/Inputs" tab. ... The parameter cannot be used with scripts using Pine Script® drawings.

    https://www.tradingview.com/pine-script-reference/v5/#fun_indicator

    Remove the resolution= and resolution_gaps= parameters from study() function call to be able to draw on the chart (boxes, lines, tables etc).