Appearance
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
- Buy and Hold - The simplest investment strategy
- SMA Crossover - Classic moving average signals
- RSI Strategy - Trade oversold and overbought conditions
📈 Momentum Strategies
Follow and profit from strong trends
- Trend Following - Comprehensive trend-following system
- Breakout Strategy - Trade price breakouts from ranges
- MACD Strategy - Moving average convergence divergence
🔄 Mean Reversion Strategies
Profit from price returning to average
- Bollinger Bounce - Trade Bollinger Band extremes
- RSI Reversal - Fade extreme RSI readings
- Pairs Trading - Statistical arbitrage between correlated assets
💼 Portfolio Strategies
Multi-asset allocation and management
- Portfolio Rebalancing - Maintain target allocations
- Risk Parity - Equal risk contribution
- Sector Rotation - Rotate between market sectors
🚀 Quick Start with Examples
Loading an Example Strategy
- Copy the code from any example page
- Paste into the strategy editor in the web interface
- Click "Run Backtest" or press
Shift+Enter
- 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 Type | Typical Win Rate | Risk Level | Best Market |
---|---|---|---|
Trend Following | 40-50% | Medium | Trending |
Mean Reversion | 60-70% | Low-Medium | Ranging |
Breakout | 35-45% | High | Volatile |
Buy & Hold | N/A | Low | Bull |
💡 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
- Start with Buy and Hold
- Learn indicators with SMA Crossover
- Add conditions with RSI Strategy
Intermediate Path
- Follow trends with Trend Following
- Trade reversals with Bollinger Bounce
- Manage risk with position sizing examples
Advanced Path
- Multi-asset with Portfolio Rebalancing
- Complex orders and bracket trades
- 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!
- Fork the repository
- Add your strategy to the appropriate category
- Include clear documentation and comments
- 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?
- Quick Start Guide - Get the platform running
- API Reference - Understand available functions
- Best Practices - Learn professional techniques
Remember: Always test thoroughly and understand the risks before trading with real money.