Strategy Variables (Strategy Designer)

Purpose

Variables serve two basic purposes:

  • Make your strategy more concise and readable.

  • Make your strategy more optimized because a variable is evaluated only once and then its result is reused.

The following comparison shows the same strategy – in the first case built with variables (on the left) and in the second without them (on the right). See for yourself:

Strategy with variables
The same strategy without variables

While the strategy with the variables might look “larger” at first glance, the actual calculation plugged into the Price input is much more readable than without the variables.

Adding Variables

You can add your variables by clicking the + button on the left side of the strategy block. A rename dialog will appear where you have to type the variable name. This will add a variable setter block into the workspace. You can plug any other block into the variable setter block which will set the variable’s value.

If you have multiple variables and try to drag a setter that has another setter underneath, you will drag both of them. To drag just a single block, hold the Ctrl (Cmd) key before dragging.

By clicking on the variable setter’s drop-down, you will see the following options:

  • Change the setter to another variable (note that you cannot have multiple setters for the same variable).

  • Rename the variable (a dialog will appear).

  • Delete the variable from the workspace – this will also delete all variable getters!

Using Variables

Each variable allows you to use a variable getter block which represents the variable’s value. You can find all variable getters in the Parameters toolbox category and drag & drop them into your workspace.

The variable represented by the getter can be easily changed by clicking the getter’s drop-down.

You can also create a variable getter by right-clicking the variable setter and selecting the ‘get {Variable}’ option.