Your code snippet is insufficient to address the problem you are describing.
Post the nBarStop code here.
On top of that, the construct itself is incorrect because when I is equal to BarCount -1, adding Sell[ i + nBars ] is an out-of-bounds access.
Plus you are implementing a look-ahead approach whereas I believe you should be using a "look-behind" to see if two bars have passed and no exit signal has occurred, then set it.
As been mentioned several times in the forum... readers here can not walk on water so readers here can not see your screen and code from miles distance as well.
Anyway this complete rule set example works just fine
Thanks fxshrat for your help - I used the code above and I am still getting a similar result...Most are fine, but a few are greater than 3 bars...see below...
@pmfiorini,
Larger numbers are shown in #Bars column to symbols which have been closed but have had data holes in between entry and exit. Also larger values are shown to those symbols that are still open and have not up to date data (last date of array smaller than set end date of analysis range) and had last entry signal at less bars before nbar stop could trigger (-> last barindex of array minus barindex of entry being smaller than nbars stop).
And that is why it is counting because not being able to exit (earlier).