Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

but i am still facing same error

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    but i am still facing same error

  2. Assistant

    Thanks for the update! The error "objects positioned xloc.bar_index cannot be drawn 500 bars in the future" usually happens when you use bar_index or a value interpreted as bar_index that points to a future bar relative to the current chart's bar.


    Why is this happening?

    Your code uses:

    box.new(
        left=higherTimeOpen,
        right=higherTimeClose,
        ...
    )
    

    But box.new() expects left and right to be either:

    • bar indices (if xloc.bar_index is used, which is the default), or
    • timestamps (if xloc.bar_time is specified).

    Since higherTimeOpen and higherTimeClose are timestamps, but you didn't specify xloc.bar_time, Pine Script treats them as bar indices, which causes the error.


    The fix: specify xloc.bar_time in box.new()

    You need to tell Pine Script explicitly that your left and right are timestamps, not bar indices.


    Corrected code snippet:

    newBox = box.new(
        left = higherTimeOpen,
        right = higherTimeClose,
        top = higherHigh,
        bottom = higherLow,
        border_color = color.red,
        border_width = 2,
        bgcolor = color.new(color.red, 90),
        xloc = xloc.bar_time  // <--- THIS IS THE CRUCIAL PART
    )
    

    Full corrected script with this fix:

    //@version=6
    indicator("Candle Breach Indicator", overlay=true, max_boxes_count=400)
    
    // Input for higher timeframe and max boxes
    higherTF = input.timeframe("60", "Higher Timeframe")
    maxBoxes = input.int(50, "Max Boxes to Display", minval=1, maxval=400)
    
    // Request higher timeframe data
    higherOpen = request.security(syminfo.tickerid, higherTF, open)
    higherHigh = request.security(syminfo.tickerid, higherTF, high)
    higherLow = request.security(syminfo.tickerid, higherTF, low)
    higherClose = request.security(syminfo.tickerid, higherTF, close)
    higherTimeOpen = request.security(syminfo.tickerid, higherTF, time)
    higherTimeClose = request.security(syminfo.tickerid, higherTF, time_close)
    
    // Calculate the condition on the higher timeframe
    prevHigh = request.security(syminfo.tickerid, higherTF, high[1])
    prevLow = request.security(syminfo.tickerid, higherTF, low[1])
    
    currentHigh = higherHigh
    currentLow = higherLow
    currentClose = higherClose
    
    breachHigh = currentHigh > prevHigh
    breachLow = currentLow < prevLow
    closeWithinRange = currentClose <= prevHigh and currentClose >= prevLow
    
    condition = (breachHigh or breachLow) and closeWithinRange
    
    // Array to store box IDs for management
    var box[] boxes = array.new_box(0)
    
    // Keep track of the last processed higher timeframe bar's open time
    var float lastProcessedTime = na
    
    // Check if the current higher timeframe bar meets the condition and hasn't been processed yet
    if condition and (na(lastProcessedTime) or higherTimeOpen != lastProcessedTime)
        // Create new box with xloc.bar_time to use timestamps for left/right
        newBox = box.new(
             left = higherTimeOpen,
             right = higherTimeClose,
             top = higherHigh,
             bottom = higherLow,
             border_color = color.red,
             border_width = 2,
             bgcolor = color.new(color.red, 90),
             xloc = xloc.bar_time  // <--- Important fix here
         )
        
        // Add the new box to our array
        array.push(boxes, newBox)
        
        // If we exceed the maximum number of boxes, delete the oldest one
        if array.size(boxes) > maxBoxes
            oldestBox = array.get(boxes, 0)
            box.delete(oldestBox)
            array.remove(boxes, 0)
        
        lastProcessedTime := higherTimeOpen
    

    Summary:

    • Always specify xloc = xloc.bar_time when using timestamps for left and right in box.new().
    • This tells Pine Script to interpret those values as timestamps, not bar indices.
    • This will prevent the "cannot draw 500 bars in the future" error.

    Try this updated script and let me know if the error persists!

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