title: How to enter a buy trade when 3 consecutive candles close above EMA?
body: <p>I'm new to pine script and I am trying to figure out how to make a trade entry with the requirement:<br>
  <strong><code>IF (3 consecutive candles close above ema 9) THEN (enter the trade)</code></strong>.</p>
  
  <p>So far, all I have is an entry signal when the EMA line crosses over the price. </p>
  
  <pre class="lang-js prettyprint-override"><code>//@version=4
  strategy("My Script", overlay = true)
  
  ma = ema(close, 9)
  
  entry() =&gt; crossover(close, ma)
  exit() =&gt; crossover(close, ma) 
  
  strategy.entry(id = "long_ma", long = true, when = entry())
  strategy.close(id = "long_ma", when = exit())
  </code></pre>
  
  <p>How can I use the 3 last candles for the entry?</p>