Valuewhen to find date & close issue

#1
AFL help - how to use Valuewhen to find date & close issue

Hi

Myself want to use valuewhen() to find the next new close
& date when it is greater than or equal to PrTgt.

Most of the time, the result are correct but in some
cases, the result date & close are incorrect. Not sure
why the result is inconsistence in the valuewhen()
function.

Even when run on past data, valuewhen give wrong
data.

Please advise if my coding is having issue.
Thank

//Part of my code

PrTgt = FinalPrice;
TrigDate = Ref(DateTime(),1);
TrigClose = Ref(Close,1);
AddColumn(TrigDate, "Confirmed Setup Date", formatDateTime);
AddColumn( TrigClose, "Confirmed Setup Close", format = 1.2);

//find next new close & date based on PrTgt
lNewClose = ValueWhen(Close >= PrTgt, Close, 0);
lNewDate = ValueWhen(Close >= PrTgt , DateTime(), 0);
AddColumn( IIf(Rev, lNewClose , Null),"Rev New Close");
AddColumn( IIf(Rev, lNewDate, Null), "Rev Finish Date", formatDateTime);
 
Last edited:

Similar threads