LASTIF(Condition) not working with REF

Dear Sirs, I do not get any Exit Long trades with following script:

Go Long

CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,10))

Exit Long

SET A=  CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,10))
SET X = LASTIF(A)
CLOSE < REF(CLOSE,X)

The objective of the above Exit script is to exit when the close price breaches the Close of bar when I went Long. Kindly suggest why there are no Exit trades shown in PI Backtest.

I'm not an expert at this, but you could try this -

Sell Script -

SET A=  CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,10))

Close < A

Not sure if you really need Lastif condition here. 

Thanks Kartik. However this won’t work because with every new candle “A” will be reset. The question is whether we can use an evaluated quantity like X in REF(close,X) ?