title: Internal Server Study Error > pivothigh / pivotlow
body: <p>I'm having a strange error with my script. I want to convert the ATR into a stochastic for the purposes of determining an appropriate lookback length for my indicators. You can ignore <code>timeframe_factor</code>; it's a function that returns an integer based on a fractal period and I've verified it's working properly.</p>
  
  <pre><code>atr_timeframe = timeframe_factor(2)
  atr_stoch_timeframe = timeframe_factor(3)
  atr = atr(atr_timeframe)
  atr_stoch = stoch(atr, highest(atr, atr_timeframe), lowest(atr, atr_timeframe), atr_stoch_timeframe) / 100
  atr_stoch_period = round(atr_stoch * atr_stoch_timeframe)
  pivot_period = atr_stoch_period[2] &gt; atr_stoch_period[1] and atr_stoch_period &gt; atr_stoch_period[1] ? atr_stoch_period[1] : atr_stoch_period
  pivot_period := pivot_period &lt; 1 ? 1 : pivot_period
  plot(pivothigh(high, pivot_period, 0))
  </code></pre>
  
  <p>The 1st assignment to <code>pivot_period</code> is for the sake of using the prior <code>pivot_period</code>'s value if a sharp uptick has occurred (beginning of day for example). I've visually verified by plotting <code>pivot_period</code> that it shows integers >= 1 on the chart - it's only when using it in <code>pivothigh</code> that the error occurs. I've also verified that there are no <code>na</code>'s on the chart by using <code>barssince</code>. The error doesn't happen if I use a static integer.</p>