GEVORDERD · DERIVATEN & ALGO

Algo Strategy Design

From hypothesis to code: signal generation, execution logic, and state management.

Market makers, dark pools, HFT en hoe de markt echt werkt.

What Makes a Strategy "Algorithmic"?

An algorithmic strategy is a set of rules that can be expressed precisely enough for a computer to execute without human intervention. The key word is precisely - "buy when it looks bullish" is not algorithmic. "Buy when the 20 EMA crosses above the 50 EMA and RSI is above 50" is algorithmic.

Every algo strategy has three core components:

  • Signal generation: What conditions trigger a trade?
  • Execution logic: How is the trade placed? (Order type, size, timing)
  • State management: What is the current position? What are the open orders? What's the P&L?

The Hypothesis-First Approach

Every strategy should start with a hypothesis about why it should work:

  • Bad: "I'll use RSI and MACD because they're popular indicators."
  • Good: "After a strong trend day, the market tends to mean-revert in the first hour of the next session. I'll fade the gap if it's larger than 1 ATR."

The hypothesis should describe a market behavior you're exploiting, not just a combination of indicators. Indicators are tools to measure the behavior - they're not the behavior itself.

Ask: "Why should this work? What market participants' behavior am I exploiting? Why hasn't this edge been arbitraged away?" If you can't answer these questions, the strategy is likely curve-fitted noise.

Signal Generation

The signal module answers: "Should I be long, short, or flat right now?"

  • Entry signals: Conditions that trigger opening a new position.
  • Exit signals: Conditions that trigger closing an existing position (take profit, stop loss, time-based exit, signal reversal).
  • Filter signals: Conditions that must be true for entry signals to be valid (e.g., "only trade during high-volume hours").
// Pseudocode: Simple signal generation function generateSignal(candles) { ema20 = calculateEMA(candles, 20); ema50 = calculateEMA(candles, 50); rsi = calculateRSI(candles, 14); if (ema20 > ema50 && rsi > 50 && rsi < 70) { return "LONG"; } else if (ema20 < ema50 && rsi < 50 && rsi > 30) { return "SHORT"; } return "FLAT"; }

Execution Logic

The execution module translates signals into actual orders:

  • Order type selection: Limit orders for better fills but risk of non-execution. Market orders for guaranteed fills but slippage.
  • Position sizing: How much to allocate based on risk parameters.
  • Order management: Cancelling stale orders, adjusting stops, scaling in/out.
  • Timing: Execute immediately on signal? Wait for confirmation? Use TWAP (Time-Weighted Average Price) to spread execution?

State Management

State management is the most underestimated component. Your bot must always know:

  • Current position (long, short, flat, and exact size)
  • Open orders (pending limits, stops)
  • Account balance and available margin
  • Recent fills and their prices
  • Error state (is the connection healthy? Are there unresolved errors?)
State desync: The most dangerous bug in algo trading is when your bot's internal state doesn't match the exchange's state. Your bot thinks it's flat, but there's actually an open position. Or it thinks an order was cancelled, but it was filled. Always reconcile state with the exchange periodically.

Common Strategy Archetypes

TypeLogicEdge source
Trend followingBuy when price is trending up, sell when trending downMarkets trend more than random walk predicts
Mean reversionBuy when price is below fair value, sell when aboveOverreactions revert to the mean
MomentumBuy recent winners, sell recent losersWinners tend to keep winning (short-term)
Market makingPlace bids and asks, profit from the spreadProviding liquidity earns the spread
Statistical arbitrageExploit price relationships between correlated assetsMispricings between related instruments

The Development Pipeline

  • 1. Hypothesis: Define the market behavior you're exploiting.
  • 2. Backtest: Test on historical data with realistic assumptions.
  • 3. Paper trade: Run live on testnet/paper account for weeks.
  • 4. Small live: Deploy with minimal capital to validate execution.
  • 5. Scale: Gradually increase size as confidence grows.
  • 6. Monitor: Continuously track performance and compare to backtest expectations.

Skipping steps in this pipeline is how people lose money. Each step catches different types of problems.

Practice

Exercise

Write a complete strategy specification (not code, just the plan) that includes:

  • Hypothesis: What behavior are you exploiting?
  • Entry signal: Exact conditions
  • Exit signal: Take profit, stop loss, time exit
  • Filters: When NOT to trade
  • Position sizing: How much per trade
  • Expected characteristics: Win rate, average R, max drawdown

Key Takeaways

  • Algo strategies need: signal generation, execution logic, state management.
  • Start with a hypothesis about market behavior, not indicator combinations.
  • State desync is the most dangerous bug - always reconcile with the exchange.
  • Follow the pipeline: hypothesis → backtest → paper → small live → scale.
  • Every strategy archetype exploits a specific market inefficiency.

Marktstructuur en deelnemers

Financiële markten bestaan uit verschillende deelnemers met verschillende doelen: retailtraders, institutionele beleggers, market makers, hedgefondsen en centrale banken.

Marktmicrostructuur

  • Market makers: Bieden liquiditeit door continu koop- en verkoopprijzen te quoteren.
  • Dark pools: Privé-handelsplatformen waar grote orders worden uitgevoerd zonder de openbare markt te beïnvloeden.
  • HFT: High-frequency trading gebruikt snelheid als competitief voordeel.

Belangrijkste punten

  • Begrijp wie de andere deelnemers zijn en wat hun motivaties zijn.
  • Market makers verdienen aan de spread, niet aan richting.
  • Institutionele orders bewegen markten — retail volgt meestal.
  • Marktstructuur beïnvloedt hoe en wanneer je orders worden uitgevoerd.

Les afgerond

Je hebt afgerond: Algo Strategy Design.