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.
In the editor
Section titled “In the editor”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.
Typical examples are states like:
WaitingLongShortCooldown
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.
State-machine branches
Section titled “State-machine branches”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.
You can nest branches as much as you want, giving you many possible states.
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.
State transitions
Section titled “State transitions”A transition should describe a meaningful change in intent:
- From
WaitingtoLongwhen an entry signal becomes active. - From
LongtoReducing exposurewhen risk conditions change. - From
ShorttoCooldownafter 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.
Connection to target-position actions
Section titled “Connection to 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 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.
Practical takeaway
Section titled “Practical takeaway”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.