'how do I resolve the pinescript warning related to calling my function on each bar

I'm brand new to pinescript, but I know I'm getting this warning because pinescript wants me to evaluate on every bar, but I only want to draw the box when my "if" statement is met.

line 20: The function 'DrawBox' should be called on each calculation for consistency. It is recommended to extract the call from this scope.

how do I adjust the code to make pinescript happy

thanks

//@version=5
indicator("Sabre Signals", overlay = true)


lineLength = ta.atr(100) * 2

DrawVerticalLine(lineColor) =>
    line.new(bar_index, high[0] + lineLength, bar_index, low[0] - lineLength, color=color.new(lineColor, 50), width = 2)
    
DrawBox() =>
    box.new(bar_index - 3, high[4], bar_index, low[4], border_color = color.new(color.green, 50), bgcolor = color.new(color.green, 90))

if bar_index > 10   // don't start until bar 10
    if high[0] > high[1] and high[1] > high[2] and high[2] > high[3]    // 3 higher highs
        if close[3] < high[4] and close[3] > low[4]                     // base bar
            //DrawVerticalLine(color.green)
            DrawBox()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source