title: PineScript - descending MACD histogram
body: <p>I am learning some <code>PineScript</code> in my free time and I find it really diificult to work with. I am basically trying to recreate a complicated indicator I wrote in <code>C#</code> and I am struggling with simple things.</p>
  
  <p>Ommiting the complicated stuff, lets say I want to draw arrows when MACD behaves like in the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/zUYjQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zUYjQ.png" alt="enter image description here"></a></p>
  
  <p>This is my current attempt, it is basically supposed to check if we are at a peak, find histogram high, find below zero columns, then above zero columns and check if they contain a higher histogram value then the current one:</p>
  
  <pre><code>[macdLine, signalLine, hist] = macd(close, 12, 26, 9)
  float ind = na
  
  if hist[2] &gt; 0 and hist[1] &lt; hist[2] and hist &lt; hist[1] and hist[3] &lt; hist[2]
      bool maxHistFound = false
      bool lowerFound = false
      bool upperFound = false
      bool candidateFound = false
      float maxHist = hist[2]
  
      for i = 1 to 1000
  
          if not maxHistFound 
              if hist[i] &lt; 0
                  maxHistFound := true
              else
                  if hist[i] &gt; maxHist
                      maxHist := hist[i]
  
          if not lowerFound
              if hist[i] &lt; 0
                  lowerFound := true
  
          if not upperFound
              if hist[i] &gt; 0
                  upperFound := true
  
          if maxHistFound and lowerFound and upperFound
              if hist[i] &gt; 0 and hist[i + 1] &lt;= hist[i] and hist[i - 1] &lt;= hist[i]
                  if hist[i] &gt; maxHist // and macdLine[i] &gt; 0 and signalLine[i] &gt; 0 and hist[i] &gt; 0.10 
                      candidateFound := true
                      maxHist := hist[i]
  
              if hist[i] &lt; 0
                  if candidateFound
                      ind := -1
                      break
  
  alertcondition(ind == -1, title='Short', message='Short')
  
  plotarrow(ind, colorup=#008000, colordown=#FF3030, transp=0, minheight=50, maxheight=50)
  </code></pre>
  
  <p>It shows the signal even if the signal is not preceeded with what I described.</p>
  
  <p><a href="https://i.stack.imgur.com/6J7Aw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6J7Aw.png" alt="enter image description here"></a></p>
  
  <p>The main problem is that I could probably fix it myself but I don't know how to properly debug in this language and I try to do it by plotting everything but plotting to debug things is riddiculus, unfortunately in my ignorance I can't find a better solution. I could probably easily find out whats going on if I knew how to stop at breakpoint in <code>PineScript</code>.</p>