title: Plotting shapes where condition is met first, but not on consecutive candles?
body: <p>I'm trying to write an indicator which produces multiple true conditions for shapes plotted. For example, a MACD cross combined with an ADX condition which looks something like this:</p>
  <pre><code>study(&quot;MACD on chart&quot;, shorttitle=&quot;MACD on Chart&quot;, overlay=true)
  
  // MACD
  // Inputs
  fast_length = input(title=&quot;Fast Length&quot;, type=input.integer, defval=6)
  slow_length = input(title=&quot;Slow Length&quot;, type=input.integer, defval=13)
  src = input(title=&quot;Source&quot;, type=input.source, defval=close)
  signal_length = input(title=&quot;Signal Smoothing&quot;, type=input.integer, minval = 1, maxval = 50, defval = 4)
  sma_source = input(title=&quot;Simple MA(Oscillator)&quot;, type=input.bool, defval=false)
  sma_signal = input(title=&quot;Simple MA(Signal Line)&quot;, type=input.bool, defval=false)
  // Calculation
  fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
  slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
  macd = fast_ma - slow_ma
  signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
  // hist = macd - signal
  
  // DMI
  // Inputs
  lensig = input(14, title=&quot;ADX Smoothing&quot;, minval=1, maxval=50)
  len = input(14, minval=1, title=&quot;DI Length&quot;)
  // Calculation
  up = change(high)
  down = -change(low)
  plusDM = na(up) ? na : (up &gt; down and up &gt; 0 ? up : 0)
  minusDM = na(down) ? na : (down &gt; up and down &gt; 0 ? down : 0)
  trur = rma(tr, len)
  plus = fixnan(100 * rma(plusDM, len) / trur)
  minus = fixnan(100 * rma(minusDM, len) / trur)
  sum = plus + minus
  adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  
  
  longCondition = macd &gt;= signal and adx &gt;= 20
  plotshape(longCondition, style=shape.labelup, size=size.tiny, color=color.new(color.green, 60), location=location.belowbar)
  
  shortCondition = signal &lt;= macd and adx &gt;= 20
  plotshape(shortCondition, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 60), location=location.abovebar)
  </code></pre>
  <p>Unfortunately this produces multiple plotted shapes on the chart, because the condition is true for, well, multiple candles. Instead it would like to have only the first occurrence where the new condition is met anew have a shape.</p>
  <p>To prevent one question: No, I can't use <code>crossover</code> in this case, because the way I use it in the script produces wrong results. The crossover is only true on the candle it actually crosses over, but the condition is set up in a way, that the actual crossover wouldn't be the right trigger candle. I hope that makes sense.</p>
  <p>Here's a visual example:</p>
  <p><a href="https://i.stack.imgur.com/dB5Az.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dB5Az.png" alt="enter image description here" /></a></p>