title: How to make convert this long assignment statement into a function in Amibroker?
body: <p>I have this long assignment statement in Amibroker.</p>
  
  <pre><code>num_times_above = iif(Ref(CLOSE, -0)&gt;Ref(CLOSE, -4) , 1, 0)
                      + iif(Ref(CLOSE, -1)&gt;Ref(CLOSE, -4), 1, 0)
                      + iif(Ref(CLOSE, -2)&gt;Ref(CLOSE, -4), 1, 0)
                      + iif(Ref(CLOSE, -3)&gt;Ref(CLOSE, -4), 1, 0)
                      + iif(Ref(CLOSE, -4)&gt;Ref(CLOSE, -4), 1, 0)
                      ;
  </code></pre>
  
  <p>I would like to convert this long statement into a generic function that accepts a parameter n.</p>
  
  <pre><code>function get_num_times_above(n)
  {
    //code
  }
  </code></pre>
  
  <p>The code on top is for the case when <code>n == 4</code>. I am stuck at this seemingly simple problem because of the array format used in Amibroker.</p>
  
  <p>if <code>n == 3</code>, the equivalent code will be;</p>
  
  <pre><code>num_times_above = iif(Ref(CLOSE, -0)&gt;Ref(CLOSE, -3) , 1, 0)
                      + iif(Ref(CLOSE, -1)&gt;Ref(CLOSE, -3), 1, 0)
                      + iif(Ref(CLOSE, -2)&gt;Ref(CLOSE, -3), 1, 0)
                      + iif(Ref(CLOSE, -3)&gt;Ref(CLOSE, -3), 1, 0)
                      ;
  </code></pre>
  
  <p>I am using Amibroker ver6.28</p>