1

Whenever there is a breakout candle I want to store the low of the bar as the stop. Then whenever price reach below the value, I want it to create an arrow and reset the array, until condition is met again (IE when stopped out it should not show more until new breakout). Otherwise It will keep to print arrows. But I cant make it work.

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

var float stop_breakout = na 

narrow = (width[0] < width[1]) and (width[0] < width[2]) and (width[0] < width[3])
breakout = narrow[1] and (close[0] > (high[1])

if (breakout == true)
    stop_breakout := low

if (close < stop_breakout)
    stop_breakout := na

plotshape(close < stop_breakout, style = shape.triangledown, location = location.abovebar, size=size.auto, color=color.red)
document
  • 13
  • 3

1 Answers1

0

Your code works just fine, but you need to use stop_breakout as the series for the plotshape function, since this is the variable that retains the value due to the var keyword.

You also missing a parenthesis on the end of the line breakout = narrow[1] and (close[0] > (high[1]). It needs to be either:

breakout = narrow[1] and (close[0] > (high[1]))

or:

breakout = narrow[1] and (close[0] > high[1])
mr_statler
  • 1,913
  • 2
  • 3
  • 14
  • `var float stop_breakout = na if (breakout == true) stop_breakout := low if (close < stop_breakout) stop_breakout := na plotchar(stop_breakout, char="x")` The problem I run into is that every single candle is marked with an X even if it has not reached the low of the breakout candle yet. Thanks for the response. – document Jan 30 '23 at 21:28