Skip to content

Strategy Examples Library

Explore our comprehensive collection of trading strategies, from simple beginner examples to advanced portfolio management techniques.

📚 Strategy Categories

🎯 Basic Strategies

Perfect for beginners learning the fundamentals

📈 Momentum Strategies

Follow and profit from strong trends

🔄 Mean Reversion Strategies

Profit from price returning to average

💼 Portfolio Strategies

Multi-asset allocation and management

🚀 Quick Start with Examples

Loading an Example Strategy

  1. Copy the code from any example page
  2. Paste into the strategy editor in the web interface
  3. Click "Run Backtest" or press Shift+Enter
  4. Analyze the results and modify as needed

Understanding Example Structure

Each example includes:

python
# Configuration Parameters (customize these)
FAST_PERIOD = 20
SLOW_PERIOD = 50

# Main strategy function
def strategy(data_contexts, portfolio, state):
    # Strategy logic here
    return order

📊 Performance Comparison

Strategy TypeTypical Win RateRisk LevelBest Market
Trend Following40-50%MediumTrending
Mean Reversion60-70%Low-MediumRanging
Breakout35-45%HighVolatile
Buy & HoldN/ALowBull

💡 Tips for Using Examples

1. Start Simple

Begin with basic strategies like SMA Crossover to understand the fundamentals before moving to complex strategies.

2. Customize Parameters

Don't use default parameters blindly. Adjust them based on:

  • Your risk tolerance
  • Market conditions
  • Asset characteristics

3. Combine Strategies

Mix concepts from different examples:

python
# Combine trend + momentum
trend_signal = sma_20 > sma_50
momentum_signal = rsi > 50
if trend_signal and momentum_signal:
    buy()

4. Add Risk Management

Always add protective measures:

python
# Add stop loss to any strategy
if position > 0 and current_price < entry_price * 0.95:
    sell_all()  # 5% stop loss

📈 Example Code Snippets

Simple Entry Logic

python
# Buy when price crosses above SMA
if data.close > data.sma(20) and position == 0:
    return buy('AAPL', 100)

Risk-Adjusted Position Sizing

python
# Size position based on volatility
volatility = calculate_volatility(data)
position_size = (portfolio.equity * 0.02) / volatility
return buy('AAPL', position_size)

Multi-Condition Exit

python
# Exit on multiple conditions
if position > 0:
    if profit > 0.10:  # Take profit at 10%
        return sell_all('AAPL')
    elif loss > 0.05:  # Stop loss at 5%
        return sell_all('AAPL')
    elif rsi > 70:  # Overbought
        return sell_all('AAPL')

🎓 Learning Path

Beginner Path

  1. Start with Buy and Hold
  2. Learn indicators with SMA Crossover
  3. Add conditions with RSI Strategy

Intermediate Path

  1. Follow trends with Trend Following
  2. Trade reversals with Bollinger Bounce
  3. Manage risk with position sizing examples

Advanced Path

  1. Multi-asset with Portfolio Rebalancing
  2. Complex orders and bracket trades
  3. Market regime adaptation strategies

🔧 Customization Guide

Changing Symbols

python
# Original
data = data_contexts['AAPL']

# Modified for multiple symbols
symbols = ['AAPL', 'GOOGL', 'MSFT']
for symbol in symbols:
    data = data_contexts[symbol]
    # Apply strategy logic

Adjusting Time Periods

python
# Faster signals (day trading)
sma_fast = data.sma(5)
sma_slow = data.sma(15)

# Slower signals (position trading)
sma_fast = data.sma(50)
sma_slow = data.sma(200)

Adding Filters

python
# Add volume filter
if volume > avg_volume * 1.5:  # High volume confirmation
    # Original signal logic here

📝 Contributing Examples

Have a great strategy to share? We welcome contributions!

  1. Fork the repository
  2. Add your strategy to the appropriate category
  3. Include clear documentation and comments
  4. Submit a pull request

⚠️ Important Disclaimers

  • Past Performance: Backtest results don't guarantee future performance
  • Risk: All trading involves risk of loss
  • Education: These examples are for educational purposes
  • No Advice: This is not financial advice

🎯 Next Steps

Ready to implement these strategies?

  1. Quick Start Guide - Get the platform running
  2. API Reference - Understand available functions
  3. Best Practices - Learn professional techniques

Remember: Always test thoroughly and understand the risks before trading with real money.

Test your trading strategies risk-free with professional backtesting.