Skip to content

Offset Function (and Square Bracket Syntax)

By Optuma Team · Updated 2022-09-13

The Offset() function can be used to calculate previous bar or tool values. The offset value is the number of lookback periods (bars by default), so the previous bar’s value would require an offset of 1, and two days ago a value of 2, etc.

To see if the current 50MA value is higher than it was 10 bars ago:

MA1 = MA(BARS=50);
MA1 > OFFSET(MA1, OFFSET=10)

Instead of using the Offset function it’s also possible to use square brackets in a formula which contain the offset value for bars. Taking the 50MA example above using the 10 period offset, it can also be expressed as follows:

MA1 = MA(BARS=50);
MA1 > MA1[10]

For open, high, low, and closing prices simply put the offset in value in the parentheses, eg the closing price 5 bars ago:

CLOSE(5) is the same as CLOSE()[5] which is the same as OFFSET(CLOSE(), OFFSET=5)

Low price 3 bars ago: LOW(3) High price 3 weeks ago: HIGH(Week(PERIODAMOUNT=1), 3)

Capture

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.