REF Function

You are here:
< All Topics

REF(Vector, Periods) 

By default all calculations are performed on the last, most recent value of a vector. The following script evaluates to true when the last open price (the current bar’s open price) is less than 30: 

OPEN < 30 

OPEN is assumed to be the current bar’s open by default. You can reference a previous value of a vector by using the REF function: 

REF(OPEN, 1) < 30 

And now the script will previous bar’s open price was less than 30. The number 1 (the second argument) tells the REF function to reference values as of one bar ago. To reference values two bars ago, simply use 2 instead of 1. The valid range for the Periods argument is 1 – 250 unless otherwise noted. 

Another way to use REF is for breakouts, since we need to compare the maximum high for the past periods and the MAX function by default includes the current period.

set 30_day_high = MAX(high,30)
set Breakout = close > REF(30_day_high,1)

Table of Contents