title: PineScript proper way of comparing previous indicator data?
body: <p>I'm trying to do an indicator on pinescript and I'm pretty much new to the language. This is the code:</p>
  <pre><code>study(&quot;Tester&quot;, overlay = true)
  
  ma = ema(close, 50)
  
  signal = (high[1] &gt; ma[1] and close[1] &lt; ma[1])? true : false
  
  plotshape(signal, location = location.abovebar, style = shape.xcross)
  </code></pre>
  <p>And my expected result is an x every time the upper wick of a candle goes above the 50 period ema but closes below it. I'm getting Xs where I can't seem to find any reason on why the condition triggers.</p>
  <p><a href="https://i.stack.imgur.com/GsJat.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GsJat.png" alt="enter image description here" /></a></p>
  <p>EDIT</p>
  <p>Code adjusted to non-shifted bar:</p>
  <pre><code>study(&quot;Tester&quot;, overlay = true)
  
  ma = ema(close, 50)
  
  signal = (high &gt; ma and close &lt; ma)? true : false
  
  plotshape(signal, location = location.abovebar, style = shape.xcross)
  </code></pre>
  <p>Image of the issue:</p>
  <p><a href="https://i.stack.imgur.com/DkuLq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DkuLq.png" alt="enter image description here" /></a></p>