Documentation
Code Reference
Everything you need to write, test, and deploy your trading strategies.
Writing Your Strategy
Code structure, syntax, and best practices
Strategy Structure
Every strategy is a Python-style class with two required methods:__init__ for setup andon_data for trading logic.
class Strategy:
"""Your strategy docstring - describe what it does"""
def __init__(self):
# Define which assets to trade - ANY ticker works
self.assets = ['AAPL', 'MSFT', 'BTC-USD', 'SPY']
# Your parameters
self.lookback = 20
self.threshold = 0.05
def on_data(self, data):
"""Called on each data update with price data for all assets"""
for asset in self.assets:
if asset not in data:
continue
# Your trading logic here
if self.should_buy(asset, data):
self.buy(asset, size=0.25) # 25% of portfolio
elif self.should_sell(asset, data):
self.close(asset)
def should_buy(self, asset, data):
# Custom helper method
return data[asset].rsi_14 < 30
def should_sell(self, asset, data):
return data[asset].rsi_14 > 70Defining Your Universe
Your code defines which assets to trade. There are no restrictions — use any ticker symbol.
# Single asset
self.asset = 'SPY'
# Multiple assets
self.assets = ['AAPL', 'MSFT', 'GOOGL']
# Crypto
self.assets = ['BTC-USD', 'ETH-USD']
# Mixed portfolio
self.assets = ['SPY', 'GLD', 'BTC-USD', 'AAPL']
Example Templates
The editor includes several example strategies. Load them to learn the patterns, then customize to make them your own.
Multi-Asset Momentum
Rank assets by momentum, hold top performers
Pairs Mean Reversion
Trade spread between correlated pairs
Trend Following
MA crossover across asset classes
RSI Multi-Asset
Buy oversold, sell overbought across universe
Crypto Momentum
Momentum with volatility filter for crypto