pine-scripttradingpine-script-v4

Plotshape and label syntax error; too many arguments


In below code, I am getting syntax error for plotshape and several for label. Even for max / min I am getting too many arguments. I used label to get the value from intraburst formula as text. Will need help to resolve these.

//@version=4 
study("Intraburst", overlay=true)

truemove = abs(open[2] - close) dayTrueHigh = max(high[1], high,
close[2]) dayTrueLow = min(low[1], low, close[2]) dayTrueRange =
dayTrueHigh - dayTrueLow intraburstLevel = truemove / dayTrueRange *
100

if intraburstLevel > 30
    plotshape(series=intraburstLevel, text="ON", style=shape.circle, location=location.abovebar, color=color.green, size=size.normal) else
    plotshape(series=intraburstLevel, text="OFF", style=shape.circle, location=location.abovebar, color=color.red, size=size.normal)

label = label.new(bar_index=0, yloc=y_top, xloc=xloc.bar_index,
text=tostring(intraburstLevel, "0.00"), size=size.large,
color=color.black) label.location = location.top label.y = y_top
label.x = x_right label.text = tostring(intraburstLevel, "0.00")

Solution

  • In a series, use a ternary operator.

    Something like that:

    plotshape(
      intraburstLevel > 30 ? intraburstLevel : na,
      text = "ON",
      style = shape.circle,
      location = location.abovebar,
      color = color.green,
      size = size.normal)
    plotshape(
      intraburstLevel <= 30 ? intraburstLevel : na,
      text = "OFF",
      style = shape.circle,
      location = location.abovebar,
      color      = color.red,
      size = size.normal)
    

    and the label

    label.new(
      bar_index,
      close,
      tostring (intraburstLevel, "##.00"),
      color     = color.black,
      textcolor = color.white)