Skip to content

Self Referencing Scripts

By Optuma Team · Updated 2020-04-03

The SELF() function allows a script to reference itself to get its previous value for use in the current calculation. Alternativley you can reference the function with [] as you would with an offset value.

E.g., a simple script that increments 1 on each bar process

A1 = 1 + Self();
A1

Or

A1 = 1 + A1[1];
A1

In this script example you can see A1 is equal to a standard moving average MA() plus 0.2, then multiplies by the previous scripts value.

A1 = MA() + 0.2 * Self();
A1;

or this script would output the same result…

A1 = MA() + 0.2 * A1[1];
A1;

In this final example this script returns the accumulated turnover divided by the accumulated volume…

t1 = TO();
v1 = VOLUME();
t2 = t1 + t2[1];
v2 = v1 + v2[1];
t2/v2

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.