title: Pinescript: How to get highest, lowest, sma, excluding specific timeframe?
body: <p>I am trying to calculate KDJ of index, <strong>excluding</strong> specific timeframe. e.g. 1130-1430. Below is the code I used to calculate KDJ and apply to 1/5/15 mins bars.</p>
  <pre><code>study(&quot;My Script&quot;)
  ilong = 10 // period
  isigK = 3
  isigD = 3
  
  c = close
  h = highest(high, ilong)
  l = lowest(low,ilong)
  RSV = 100*((c-l)/(h-l))
  pK = sma(RSV, isigK)
  pD = sma(pK, isigD)
  pJ = 3 * pK - 2 * pD
   
  plot(pK, color=color.red)
  plot(pD, color=color.blue)
  plot(pJ, color=color.green)
  
  timeinrange(res, sess) =&gt; time(res, sess) != 0
  bgcolor(timeinrange(timeframe.period, &quot;1130-1430&quot;) ? color.silver : na, transp=0)
  
  </code></pre>
  <p>However, I dont know how to exclude data within 1130-1430 during the calculation of highest/lowest/sma as part of calculation. For example, I want</p>
  <ul>
  <li>calculations of 1430 are based on 1121-1130  ( same as calculations of 1130 )</li>
  <li>calculations of 1431 are based on 1122-1130 and 1430</li>
  <li>calculations of 1432 are based on 1123-1130 and 1430-1431</li>
  <li>calculations of 1433 are based on 1124-1130 and 1430-1432</li>
  <li>...</li>
  <li>calculations of 1439 are based on 1130-1130 and 1430-1439</li>
  <li>calculations of 1440 are based on 1431-1440</li>
  </ul>