Skip to content

Strategy anatomy

State machines

In Structure, a strategy can expose states to make its behavior easier to understand. Those states describe the strategy’s current intent, and the state machine determines when it stays there or moves somewhere else.

State machines are useful because they turn a stream of evaluated values into recognizable behavior. Instead of hiding intent inside one large calculation, the revision names the states it can be in and the conditions that move it between them.

When you open a strategy revision, the states live in their own pane. This is where you define the named modes the revision can move between.

The states pane in a strategy revision, showing the list of strategy states.

Typical examples are states like:

  • Waiting
  • Long
  • Short
  • Cooldown

The right set of states depends on the strategy. A market-making strategy, a trend-following strategy, and a risk-reduction strategy may all use different state names. The important point is that each state should have a clear purpose.

The state machine is where the strategy decides whether it should stay in its current state, move to another one, or prepare the values a strategy action needs.

You usually start from a simple branch. The branch condition expects a Bool label from the graph. In the example below, the branch is fed by a ConstBool; real strategies usually use computed labels such as signal, risk, or cooldown checks.

A branch in the strategy state machine.

You can nest branches as much as you want, giving you many possible states.

Creating a new branch in the strategy state machine.
Nested branches in the strategy state machine.

Branch order and branch conditions should be easy to explain. If two branches overlap, the revision becomes harder to review because the intended behavior is less obvious.

A transition should describe a meaningful change in intent:

  • From Waiting to Long when an entry signal becomes active.
  • From Long to Reducing exposure when risk conditions change.
  • From Short to Cooldown after an exit condition.

The graph computes the values. Labels expose the values. The state machine uses those labels to choose the next state.

This separation makes it easier to troubleshoot a revision:

  • If a label has the wrong value, inspect the graph path that produced it.
  • If the label is correct but the state is wrong, inspect the state machine.
  • If the state is correct but the resulting exposure is wrong, inspect target-position actions.

Once your state machine is set up, you can define strategy actions for each state. Today, the public strategy action type is the target-position action. Like state branch conditions, quantity must be fed into a Label node as a Numeric data type.

The Actions pane using a target position value produced by the graph.

The state machine describes intent. Target-position actions describe the exposure associated with that intent.

Today, Structure’s public strategy action type is the target-position action. Strategies emit target positions, and the Target Position Executor manages order activity to move account positions toward those targets.

Direct order actions are roadmap functionality. When introduced, they will let strategies place, cancel, and modify orders directly for strategies that need order-level control.

State machines are easiest to understand when each state has a clear purpose and each state-machine branch has a clear reason. If you can explain why the strategy changes state, the revision is usually much easier to trust.

Once the states are clear, the next question is what exposure each state should express. That is the focus of Actions and target-position actions.