title: In Pine-script, how to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator?
body: <p>In Pine-script, I need to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator.</p>
  
  <p>I have tried various methods of coding this resulting in either an internal server error or compile errors.</p>
  
  <p>Pseudo-code:</p>
  
  <pre><code>If currentbar &gt;= upperthreshold
     indicatorvalue = value1
  Elseif currentbar &lt;= lowerthreshold
     indicatorvalue = value2
  Else
     indicatorvalue = indicatorvalue[currentbar-1]
  </code></pre>
  
  <p>The expected result is an indicator plot alternating between the 2 values in the pseudo-code provided, since the value of each bar falling between the thresholds is set to the value of the preceding bar.</p>