Skip to main content
Skip table of contents

The "With" function

The With function can be used to reuse calculated values several times without having to assign them to variables. It also makes it easier to transfer expressions to other formulas if the input for the transferred expressions in the new formula is not available from the outset, but must first be calculated. Generally speaking, With evaluates an expression under the context of a new object to be specified.

Beispiel 1

The expression (High+Low)/2 describes the average of high and low values for a security as a time series, or in tables the last value of this time series. If a column with this calculation formula is to be included in a limit list as a mid-price display, the situation arises that the High and Low functions cannot be applied directly to a limit object and the expression mentioned in limit tables is undefined.

The formula:

CODE
$wp:=wp;
$wp.High+$wp.Low)/2


describes a working variant of this formula in this case, whereby the variable"$wp" is inserted for each access to the security. Using the function With function makes it easier to convert the formula:

CODE
With[WP]((High+Low)/2) oder auch
WP.with((High+Low)/2)

Beispiel 2

Another application example can be found in the following expression, which refers to securities and calculates a momentum:

CODE
With[Close] (object-Before[1])


Here is With is used to avoid the double calculation of the function Close function.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.