title: TradingView Pine Script : check previous strategy.entry price before new entry
body: <p>Someone asked a similar question with no response and I am not allowed to add to it.</p>
  
  <p><a href="https://stackoverflow.com/questions/48958139/tradingview-pine-script-save-close-price-at-time-of-strategy-entry">Tradingview Pine script save close price at time of strategy entry</a></p>
  
  <p>I am trying to build a strategy that will buy multiple times (pyramiding) to average down before closing but I want to check the previous entry price to make sure it's less by a configured percentage.</p>
  
  <p>What I have so far:</p>
  
  <pre><code>lastBuy=0
  
  if (condition)
      if (lastBuy==0)
          lastBuy=close
          strategy.entry("buy", true)
      else
          if ((close*1.01)&lt;lastBuy)
              lastBuy=close
              strategy.entry("buy", true)
  </code></pre>
  
  <p>Each time the code is passed it resets lastBuy back to zero and I never get to check the previous close price. If I don't set this I get undeclared error. </p>
  
  <p>Thanks in advance for any help!</p>