How Can We Help?

LASTIFS Function

You are here:
< All Topics

LASTIFS(Condtion) 

Similar to COUNTIFS, except LASTIFS returns a vector containing the number of days since the last time the specified condition evaluated to TRUE. The count is reset to zero each time the condition evaluates to TRUE. 

Syntax:
LASTIFS(condition)
or
LASTIFS(condition, reset condition)

Example: 

SET SMA = SMA(CLOSE,14)
SET SELL = CROSSOVER(CLOSE,SMA)
//Standard version
LASTIFS(CLOSE < REF(CLOSE, 1)) 
or
//With reset version
LASTIFS(CLOSE < REF(CLOSE, 1),SELL) 

The script returns a vector that increases in value for each bar where the closing price was not less than the previous closing price. When the condition evaluates to TRUE, meaning the closing price was less than the previous closing price. On the reset version, the count resets on the sell condition.

Table of Contents