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

Asked by Radhesh Joshi · SOLVED
1 reply 375 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

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?

Posted Aug 8
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    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.

    Verified Solution
      Markdown supported · ```json for code blocks · paste or drop screenshots

      Be specific and kind. Never share API keys, passwords or personal account details.

      Welcome to the community

      Log in or create your account in under a minute.

      1. 1Mobile
      2. 2E-mail
      3. 3Password
      +91

      Have a password?

      By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.