Someone asked a similar question with no response and I am not allowed to add to it.
Tradingview Pine script save close price at time of strategy entry
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.
What I have so far:
lastBuy=0
if (condition)
if (lastBuy==0)
lastBuy=close
strategy.entry("buy", true)
else
if ((close*1.01)<lastBuy)
lastBuy=close
strategy.entry("buy", true)
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.
Thanks in advance for any help!