title: When are strategy.entry and strategy.exit executed?
body: <p>I am trying to count the total number of trades done by a dummy strategy in <strong>backtesting</strong> but I have trouble counting the trades that enter and exit at the exact same time.</p>
  <p>This is the strategy:</p>
  <pre><code>//@version=5
  strategy(&quot;Super/MACD/RSI&quot;, overlay=false)
  
  import keio/console/2 as c
  var log = c.init()
  
  // INDICATORS
  [macdline, signalline, histline] = ta.macd(close, 12, 26, 9)
  [supertrend, direction] = ta.supertrend(3, 10)
  rsi = ta.rsi(close, 14)
  
  // SIGNAL
  buysignal = ta.crossover(macdline, signalline) and close &gt; supertrend and rsi &lt; 65 
  
  // SL &amp; TP
  var longSL = 0.0
  var longTP = 0.0
  if buysignal
      longSL := close - close * 0.02
      longTP := close + close * 0.06
  
  // STRATEGY
  if buysignal
      strategy.entry(id = &quot;Long&quot;, direction=strategy.long)
  strategy.exit(id = &quot;Long Exit&quot;, from_entry = &quot;Long&quot;, limit=longTP, stop=longSL)
  
  // DEBBUG
  var bool intrade = false
  var bool tradecounted = false
  var int entries = 0
  
  if strategy.opentrades != 0
  // if strategy.position_size &gt; 0
      intrade := true
  else
      intrade := false
      tradecounted := false
  
  if intrade and not tradecounted
      entries += 1
      date = timestamp(year, month, dayofmonth, hour)
      log := c.print(log,&quot;Entry : &quot; + str.tostring(entries) + &quot; : &quot; + str.format(&quot;{0,date,yyyy.MM.dd HH:mm}&quot;, date))
      tradecounted := true
  </code></pre>
  <p>If you execute it you will see that it prints the exact same entries as the strategy tester, except for those that enter and finish at the exact same time. Those are missing.</p>
  <p>Even if I put the line</p>
  <pre><code>strategy.exit(id = &quot;Long Exit&quot;, from_entry = &quot;Long&quot;, limit=longTP, stop=longSL)
  </code></pre>
  <p>At the end of the script the result is still the same.</p>
  <p>Is the strategy.* related code executed separately from the rest of the code when backtesting?</p>