Skip to main content

What We’re Building

A dual SMA (Simple Moving Average) crossover strategy on Binance futures:
  • Buy when the fast SMA crosses above the slow SMA (bullish momentum)
  • Sell when the fast SMA crosses below the slow SMA (bearish momentum)
  • Trade BTC and ETH with 3× leverage
This tutorial explains every step in detail. If you want just the code, see the Quickstart.

Step 1: Discovery

First, explore what’s available:

Step 2: Symbol-Source Mapping

Define which symbols trade on which exchange. This mapping determines data routing and execution venues:
Why SymbolSourceMap? In multi-exchange strategies, you need to know which symbols belong to which exchange — for both data loading and order routing. Even for single-exchange strategies, this explicit mapping prevents configuration errors.

Step 3: Build the Graph

The graph is a DAG (Directed Acyclic Graph) of operators. Data flows from FIELD inputs (market data) through computation nodes to intentions (trading orders).

3a: Imports

3b: FIELD Input

Every graph starts with a FIELD input — raw market data from an exchange:

3c: Indicators

SMA operators compute moving averages from the close price input:
Each operator receives a TaggedArray of shape (lookback, n_symbols) — in this case, (50, 2) for 50 ticks of BTC and ETH close prices. The SMA operator computes the average over the span most recent values.

3d: Signal

The crossover alpha generates a trading signal when fast SMA crosses slow SMA:
Output: A TaggedArray where positive values indicate bullish (fast > slow) and negative values indicate bearish (fast < slow). The magnitude reflects the strength of the crossover.

3e: Transform

Convert the signal into portfolio weights:
EqualWeight normalizes signals to sum to 1.0 (long-only) or handles long/short allocations. Each symbol gets an equal share of the capital.

3f: Portfolio Accounting

Calculate equity (total account value) from STATE data:
STATE inputs (e.g., STATE:binance:futures:cash) pull portfolio data from the executor — cash balance, position quantities, entry prices. These are updated after every fill.

3g: Intention (Order Generation)

Convert weights into actual trading intentions:
FuturesTargetPositionIntention computes the delta between current positions and target positions, then generates orders to close the gap. This is target-position trading: you declare where you want to be, not what to buy/sell.

Step 4: Configure the Spec

Key parameters explained:
  • output_nodes=["equity", "signal"] — Track these nodes for post-analysis with to_dataframe()
  • execution_price_source="ohlcv" — Use OHLCV close price for fill simulation
  • debug=True — Store all tick results (required for to_dataframe())
  • Funding rates are auto-injected for futures accounts — no manual configuration needed

Step 5: Run and Analyze

The Complete Graph

Here’s how data flows through the graph we built:

Next Steps

Backtest to Live

Submit this strategy and run it in paper or live mode on the platform

Multi-Factor Strategy

Combine multiple alpha signals with risk management

Operator Reference

Browse all available operators

Backtesting Accuracy

Understand cost models, funding, and liquidation