title: Pinescript (tradingview) Stop lost not triggering in backtest
body: <p>I have a strategy that should sell when 1 condition is reach or when SL is hit, but my backtest show that the trade continue even if the SL is hit.</p>
  
  <pre><code>//@version=4
  strategy(title="Extreme highs and lows", calc_on_order_fills=true,calc_on_every_tick =true, initial_capital=21000,commission_value=.1,overlay = true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
  
  // Backtest Input
  FromYear = input(2015, "Backtest Start Year")
  FromMonth = input(1, "Backtest Start Month")
  FromDay = input(1, "Backtest Start Day")
  ToYear = input(2999, "Backtest End Year")
  ToMonth = input(1, "Backtest End Month")
  ToDay = input(1, "Backtest End Day")
  
  // Backtest Setting
  start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
  finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
  window()  =&gt; time &gt;= start and time &lt;= finish ? true : false 
  
  
  // Input options
  hiLen = input(title="High Length", type=input.integer, defval=20)
  loLen = input(title="Low Length", type=input.integer, defval=20)
  
  // SL input
  SL =  input(defval=2.0, title='Stop Loss %', type=input.float)
  
  // Stop loss setting
  StopLossLong = strategy.position_avg_price * (1 - SL/100)
  StopLossShort = strategy.position_avg_price * (1 + SL/100)
  
  // Calculate values
  hiHighs = highest(high, hiLen)[1]
  loLows = lowest(low, loLen)[2]
  
  // Plot values on the chart
  plot(series=hiHighs, color=color.green, linewidth=2)
  plot(series=loLows, color=color.red, linewidth=2)
  
  // Highlight new highs and lows with
  // a coloured background
  bgColour = high &gt; hiHighs ? color.teal : low &lt; loLows ? color.maroon : na
  
  bgcolor(color=bgColour, transp=90)
  
  //Trade condition
  long= close &gt; hiHighs
  short= close &lt; loLows
  // StopLoss Long Signal
  SLLongCondition = crossunder(close, StopLossLong)
  // StopLoss Short Signal
  SLShortCondition = crossover(close, StopLossShort)
  
  // Strategy
  strategy.entry("long", strategy.long, when = long and window())
  strategy.close("long", when = short or SLLonCondition and window())
  strategy.close("long", when = SLLongCondition and window())
  
  // Plot Stoploss
  conditionLong = barssince(long)
  plot(conditionLong ? StopLossLong : na, color=color.red, style=plot.style_linebr, linewidth=2)
  </code></pre>
  
  <p>I have tried without that line also: strategy.close("long", when = SLLongCondition and window())</p>