title: Pine script - Count bar from condition
body: <p>How can I have a bar number from when a condition is true?
  barssince give me alway value 0</p>
  <p>I need for create a series of trailing stop loss.</p>
  <p>Here it is my code</p>
  <pre><code>    SMA16=sma(close,16)
  SMA50=sma(close,50)
  plot(SMA16,color=color.red)
  plot(SMA50,color=color.blue)
  
  
  
  longcondition=crossover(SMA16,SMA50)
  
  count = barssince(longcondition)
  
  SL=valuewhen(longcondition,close,0)*0.5
  TSL = SL + highest(high,count)-valuewhen(longcondition,close,0)
  
  plot(TSL,color=color.navy)    
  plot(SL,color=color.black)
  </code></pre>