title: Tradingview pine-script backtesting rsi
body: <p>I'm back-testing and RSI(6) strategy. I want it to buy on the SECOND CROSSING of the 30 oversold line(When it is going back up) and Sell on the SECOND CROSSING of the 70 oversold line(when it is going down). I can only get it to buy and sell when it immediately crosses the overbought/oversold line which is not why I'm trying to do. I'm also trying to add a 10% stop loss. Does anyone have any ideas how to implement those orders? This is my code so far.</p>
  <pre><code>strategy(&quot;RSI&quot;, overlay = true)
  
  longcon = rsi(close, 6) &lt; 30 
  
  closecon = rsi(close,6) &gt; 70
  
  //backtest from 2015
  _year = 2015
  
  strategy.entry(&quot;long&quot;, strategy.long, when = longcon and year &gt;= _year)
  
  strategy.close(&quot;long&quot;, when = closecon)
  
  plot(close)
  </code></pre>