LastValue should not be used in backtest, was: Simplest code doesn't work

Hi !
I'm trying to adjust buyprice so stoporder to initiate long could be executed at more correct price if we have gap . It is as simple as possible but still doesn't work, price is not adjusted. Could someone help ?

entrylongprice=Ref( HHV(High,100) ,-1);
if (  (LastValue(O)>LastValue(entrylongprice)) ) {entrylongprice= O;}

Thanks a lot in advance..

Your code is simply incorrect. You are using LastValue which is big mistake. This function should never be used in backtest. For correct coding see
See also and