Home Forums Trading view How can I draw trend lines, boxes, and labels programmatically in Pine Script?

How can I draw trend lines, boxes, and labels programmatically in Pine Script?

  • Author
    Posts
    • I’m creating a custom TradingView indicator and want to mark important levels and signals directly on the chart using Pine Script.

      I want to draw things like trend lines, rectangular zones, horizontal levels, and text or signal markers programmatically.

      What are the main Pine Script functions I should use for this?

    • Yes sir, Pine Script provides several built-in functions for drawing objects and visual markers directly on the chart.

      -Line:
      line.new() is used to draw trend lines or connect two price points.

      -Box:
      box.new() is useful for creating rectangular zones such as support, resistance, supply, or demand areas.

      -Label:
      label.new() allows you to display text or custom markers at a specific price and bar.

      -Plotshape:
      plotshape() is useful for showing simple Buy/Sell arrows, triangles, or other predefined shapes when a condition is true.

      -Horizontal Line:
      hline() is used to draw a fixed horizontal level, such as an RSI level at 70 or 30.

      For example:

      //@version=6
      indicator("Drawing Example", overlay=true)
      
      buySignal = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
      
      plotshape(buySignal, title="Buy", style=shape.triangleup, location=location.belowbar, text="BUY")
      
      hline(100, "Level")
      
      if buySignal
          label.new(bar_index, low, "BUY")

      If you need dynamic drawings that are created and positioned using specific bar and price coordinates, functions like line.new(), box.new(), and label.new() are more suitable.

      For simple signal markers, plotshape() is usually easier.

      For fixed horizontal levels, hline() is the appropriate choice.

      So in simple terms:

      -> line.new() → Dynamic lines and trend lines

      -> box.new() → Rectangular zones

      -> label.new() → Text and custom markers

      -> plotshape() → Signal shapes

      -> hline() → Fixed horizontal levels

      These functions allow you to turn a basic Pine Script indicator into a much more visual and informative chart.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top