Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

this must be a horizontal line i can click and plot anywhere i want to on the chart.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    this must be a horizontal line i can click and plot anywhere i want to on the chart.

  2. Assistant

    Thanks for the clarification!

    You're asking for a horizontal line that you can freely draw manually anywhere on the chart, and then the script should detect when the price closes above or below that horizontal line, and send an alert.

    Unfortunately, Pine Script does not currently support detecting user-drawn objects (like horizontal lines or trendlines drawn directly on the chart using the drawing tools). It can only interact with objects that are created programmatically in the script. So you can’t detect when price crosses a manually drawn (GUI) line using Pine Script.

    ✅ Workaround — Simulate Manual Line with a Draggable Horizontal Line

    We can simulate a horizontal line by creating a line in Pine Script and allowing you to set the price value manually using an input box. You won't click on the chart to place it, but you can type in the exact price, optionally drag the line height, and get alerts when the price closes across that level.

    Here’s how you can do it:


    ✅ Pine Script: Draggable Alert Line with Alerts on Cross

    //@version=5
    indicator("Manual Alert Horizontal Line", overlay=true)
    
    // === USER INPUT ===
    // Use an input box to set the horizontal line level
    alert_price = input.float(defval=close, title="Horizontal Line Price Level", step=0.5)
    
    // Draw horizontal line (persisted)
    var line alert_line = line.new(x1=bar_index, y1=alert_price, x2=bar_index + 1, y2=alert_price, 
        color=color.orange, width=2, extend=extend.right)
    line.set_y1(alert_line, alert_price)
    line.set_y2(alert_line, alert_price)
    
    // Detect cross above/under on candle close
    cross_above = ta.crossover(close, alert_price)
    cross_below = ta.crossunder(close, alert_price)
    
    // Plot shapes for visual indication
    plotshape(cross_above, title="Price Closed Above Line", location=location.belowbar,
         shape=shape.triangleup, color=color.green, size=size.small)
    plotshape(cross_below, title="Price Closed Below Line", location=location.abovebar,
         shape=shape.triangledown, color=color.red, size=size.small)
    
    // Alert Conditions
    alertcondition(cross_above, title="Price Crossed Above Line", message="Price has CLOSED above the set horizontal line.")
    alertcondition(cross_below, title="Price Crossed Below Line", message="Price has CLOSED below the set horizontal line.")
    
    // Optional label showing current level
    label.new(bar_index, alert_price, "Alert Line @ " + str.tostring(alert_price), yloc=yloc.price, style=label.style_label_left, textcolor=color.black, size=size.tiny, color=color.orange)
    

    💡 How to Use:

    1. Copy & paste into Pine Script editor.
    2. Add the indicator to your 4H chart (or any timeframe if you want).
    3. In the script input box on the side panel, manually set the desired price for the line (e.g., 3000).
    4. Add an alert using TradingView’s alert menu:
      • Condition: Select this indicator.
      • Trigger: "Price Crossed Above Line" and/or "Price Crossed Below Line"
      • Choose “Once per bar close” for accurate close detection
      • Enable your desired delivery options (email, SMS, app notification)

    🔔 Optional Enhancements:

    • Enable timeframe filtering if you only want it to work on the 4h chart:
    is4H = (timeframe.period == "240")
    cross_above := is4H ? ta.crossover(close, alert_price) : false
    cross_below := is4H ? ta.crossunder(close, alert_price) : false
    

    🔒 Limitations:

    • You can't click to draw a line manually and have the script read its location.
    • Pine is sandboxed and can't access native drawing/GUI objects.
    • Using an input is the only safe and script-accessible way to simulate this behavior.

    Let me know if you'd like multiple lines, alert delays, or timeframe-based filters!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.