Skip to main content
Track Rule-based entry
8 / 14
Library

2005issue C041-4

State-locked rules for mechanical trading

A mechanical trading system can be built as a finite state machine. The procedure occupies one current state at a time, and only that regime’s rules decide whether a moving-average event may open, add to, short, or leave a position.

  • A finite state machine occupies only one current state at a time, and only that state’s rules are checked on each new observation.
  • A transition event is a stated condition that moves the procedure to a named next regime; the state diagram does not encode why the move occurs.
  • Buy, add, and sell can be written as transitory states that complete an order and then enter a hold state.
  • Once the rules are specified, historical observations can be applied to backtest the full entry-hold-exit procedure, and the same state discipline can be followed by hand.
Entries in this reading3 entries

Build the system as named regimes

A mechanical trading system is a decision procedure whose entry, exit, add, and abstention actions are fully specified as one testable sequence. Construction can follow a finite state machine: a model that lists every allowed regime of the procedure and the events that move it from one regime to another.

The procedure occupies only one state at a time. That occupied regime is the current state, and only that regime’s rules are evaluated.

Events belong to the current state

A state diagram does not encode why a transition occurs. The implementing procedure must supply the event rules. A transition event is a stated condition that, if true in the current regime, moves the procedure to a named next regime.

A mechanical trading machine can include start and stop states so opening and leaving a position are explicit transitions. Later actions then depend on both the indicators and the current state.

Rules attached to the current state can be checked on each new observation, using session closes for a daily horizon or each incoming datapoint when a live feed is attached. Different states need not share the same indicators or decision rules. Each regime can carry tests chosen for that state.

A rule-based entry is legal only when the active state’s conditions are met, not whenever an indicator looks attractive.

An illustrated moving-average rule set

A moving average is a lookback summary of ordered prices used as the baseline that buy and sell events must cross. One illustrated rule set treats a close moving above a moving average as a buy event and a close moving below that average as a sell event.

The same construction can add after a 5 percent retreat that rebounds without crossing the average, and can authorize a short after a 5 percent recovery that fails to recross the average.

Buy, add, and sell can be written as transitory states. A transitory state is a brief regime used only to complete an action such as an order, after which the procedure moves on immediately. Those momentary states complete an order and then enter a hold state, where the procedure remains until a later rule fires. A hold state keeps an existing position until a later rule authorizes a new transition.

Write the control structure, then walk it

The control structure can be coded with chained conditionals, a case selection on a stored current-state variable, or a table-driven engine when the machine is complex or rules must be user-defined.

Once the rules are specified, historical observations can be applied to the machine to backtest the full entry-hold-exit procedure. The same state discipline can be followed by hand.

Educational research material, not investment advice. Historical source context does not establish present-day performance.
8 of 14 in the Rule-based entry track
20071-9 pp.Next on Rule-based entrySame-session long entry from a moving-average filterA 34-period simple moving average of closes is the lookback used as the price filter.
All readings on this track · 14 readings
  1. 1990Moving-average direction, range penetration, and a dollar stop
  2. 1990Rally and reaction day signals as a mechanical stock system
  3. 1991Constructing steppable currency games with stop alerts
  4. 1995Trading as a business: a case study of preparation and rule-based entry
  5. 1997Bond timing rules as one testable procedure
  6. 2000Rule-based moving average commentary as a testable filter
  7. 2004Constructing a fifteen-bar trend trigger as a next-open system
  8. 2005State-locked rules for mechanical trading
  9. 2007Same-session long entry from a moving-average filter
  10. 2012Liquidity, share count, and stop-trigger costs
  11. 2012Monthly eight-bar average entry and exit rules
  12. 2012Constructing a simple moving average filter with fixed crossing rules
  13. 2014A two-average brick crossover is not yet a trading system
  14. 2020Reject long-bar entries driven by volatility fear of missing out
All 292 readings tagged Rule-based entry
Also on Rule-based entry5 readings