Skip to content

Latest commit

 

History

290 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlgoAgent Trading Strategies - Project Complete ✅

Mission Accomplished!

Successfully built 10 standalone trading strategy bots with real market data backtesting capabilities.


📁 Project Structure

C:\Users\nyaga\Documents\AlgoAgent\
├── strategies/
│   ├── 01_rsi_momentum.py         (5,991 bytes)
│   ├── 02_macd_crossover.py       (6,560 bytes)
│   ├── 03_bollinger_bands.py      (6,292 bytes)
│   ├── 04_ma_crossover.py         (6,526 bytes)
│   ├── 05_stochastic.py           (6,710 bytes)
│   ├── 06_atr_volatility.py       (6,734 bytes)
│   ├── 07_support_resistance.py   (7,786 bytes)
│   ├── 08_price_action.py         (7,374 bytes)
│   ├── 09_vwap.py                 (6,604 bytes)
│   └── 10_ichimoku.py             (9,457 bytes)
├── run_all_backtests.py
├── BACKTEST_SUMMARY.md
└── README.md (this file)

✅ Requirements Fulfilled

1. Single Source of Truth ✅

  • Each strategy uses identical logic for backtesting AND live trading
  • on_bar() method processes bars the same way regardless of mode
  • No separate backtest vs live code paths

2. Real Market Data (1 Year) ✅

  • Data Source: yfinance API
  • Symbol: EURUSD=X (major forex pair)
  • Date Range: February 3, 2025 to February 3, 2026 (exactly 1 year from today)
  • Timeframe: 1H candles (hourly), with daily fallback if unavailable
  • Data Points: ~6,149 hourly bars fetched successfully

3. Standalone & Executable ✅

  • Each .py file runs independently
  • No cross-dependencies between strategy files
  • Direct execution: python strategies/01_rsi_momentum.py

4. Complete Backtest Framework ✅

Every strategy file includes:

  • Strategy class with parameters
  • Indicator calculation methods
  • on_bar() for bar-by-bar processing
  • should_enter() and should_exit() for signal validation
  • run_backtest() function with full execution
  • Performance metrics calculation:
    • Total Trades
    • Win Rate (%)
    • ROI (%)
    • Max Drawdown (%)
    • Sharpe Ratio

🎯 10 Strategies Built

# Strategy File Indicator
1 RSI Momentum 01_rsi_momentum.py 14-period RSI
2 MACD Crossover 02_macd_crossover.py MACD (12,26,9)
3 Bollinger Bands 03_bollinger_bands.py BB (20, 2σ)
4 MA Crossover 04_ma_crossover.py EMA 9/21
5 Stochastic 05_stochastic.py Stochastic (14,3)
6 ATR Volatility 06_atr_volatility.py ATR (14)
7 Support/Resistance 07_support_resistance.py Level detection
8 Price Action 08_price_action.py Candlestick patterns
9 VWAP 09_vwap.py Volume-weighted price
10 Ichimoku Cloud 10_ichimoku.py Full Ichimoku suite

🚀 Quick Start

Test a Single Strategy:

cd C:\Users\nyaga\Documents\AlgoAgent\strategies
python 01_rsi_momentum.py

Run All Backtests:

cd C:\Users\nyaga\Documents\AlgoAgent
python run_all_backtests.py

Use in Live Trading:

from strategies.01_rsi_momentum import RSIStrategy

# Initialize
strategy = RSIStrategy(symbol='EURUSD=X', period=14)

# On each new bar (from your broker's data feed)
signal = strategy.on_bar(current_bar, rsi_value)

if signal == 'BUY':
    # Execute buy order
    pass
elif signal == 'SELL':
    # Execute sell order
    pass

📊 Code Architecture

Each strategy follows this unified pattern:

class StrategyName:
    def __init__(self, symbol, *params):
        """Initialize with trading parameters"""
        self.position = None  # Track current position
        self.entry_price = 0
        
    def calculate_indicator(self, data):
        """Calculate technical indicators from OHLCV data"""
        return indicator_values
    
    def on_bar(self, bar, *indicator_values):
        """
        🎯 CORE LOGIC - Same for backtest & live
        Process each bar and return signal
        Returns: 'BUY', 'SELL', or None
        """
        signal = None
        
        # Entry logic
        if self.position is None and entry_condition:
            signal = 'BUY'
            self.position = 'LONG'
            
        # Exit logic
        elif self.position == 'LONG' and exit_condition:
            signal = 'SELL'
            self.position = None
            
        return signal
    
    def should_enter(self, bar, *indicators):
        """Validate entry conditions"""
        return boolean
    
    def should_exit(self, bar, *indicators):
        """Validate exit conditions"""
        return boolean

def run_backtest(symbol='EURUSD=X', start_date='2025-02-03', end_date='2026-02-03'):
    """
    Execute historical backtest
    1. Fetch data via yfinance
    2. Calculate indicators
    3. Loop through bars calling on_bar()
    4. Track trades and equity
    5. Calculate and print performance metrics
    """
    # ... implementation

📈 Performance Metrics

Each backtest calculates:

  1. Total Trades: Complete buy/sell cycles
  2. Win Rate: (winning_trades / total_trades) × 100
  3. ROI: ((final_capital - initial_capital) / initial_capital) × 100
  4. Max Drawdown: max((equity - running_max) / running_max)
  5. Sharpe Ratio: (mean_return / std_return) × √252 (annualized)

Starting capital: $10,000


🔧 Dependencies

Install required packages:

pip install yfinance pandas numpy

Already installed in your environment ✅


💡 Next Steps

  1. Run backtests - Test each strategy to see historical performance
  2. Compare results - Identify which strategies work best for EUR/USD
  3. Parameter optimization - Tune indicator periods and thresholds
  4. Add risk management - Position sizing, stop losses, take profits
  5. Paper trade - Test with live data feed (no real money)
  6. Go live - Connect to broker API (MetaTrader, IBKR, Alpaca, etc.)

📝 Important Notes

  • Data limitations: yfinance forex data may be limited; strategies handle fallback to daily data
  • No slippage modeled: Backtest assumes exact fills at close prices
  • No transaction costs: Add broker spread/commission for realistic results
  • Overfitting risk: Past performance ≠ future results; validate on out-of-sample data
  • Time zones: Data timestamps in UTC; adjust for your local market hours

🎉 Project Summary

Status: ✅ COMPLETE

Deliverables:

  • ✅ 10 standalone strategy files (70KB total)
  • ✅ Master backtest runner
  • ✅ Comprehensive documentation
  • ✅ Real market data integration (yfinance)
  • ✅ Unified backtesting/live trading architecture
  • ✅ Performance metrics framework

Date Completed: February 3, 2026

Location: C:\Users\nyaga\Documents\AlgoAgent\


📚 Additional Resources


Ready for backtesting and live trading deployment! 🚀

For questions or modifications, check the individual strategy files - each is fully documented with inline comments.

Releases

Packages

Used by

Contributors

Languages