gym-mtsim  by AminHP

OpenAI Gym trading env for MetaTrader 5, enabling RL-based trading algorithms

created 3 years ago
483 stars

Top 64.4% on sourcepulse

GitHubView on GitHub
Project Summary

This project provides a flexible, general-purpose simulator and OpenAI Gym environment for algorithmic trading strategies using the MetaTrader 5 platform. It caters to reinforcement learning researchers and traders looking to backtest and analyze strategies with a focus on code readability and end-to-end trading process management.

How It Works

The core is MtSimulator, which mimics MetaTrader 5's trading logic, including order management, balance, equity, and margin calculations. It can download historical data via the MetaTrader5 Python package (Windows-only) or use custom data sources. The MtEnv class wraps MtSimulator into a standard Gym environment, processing historical price data into features and defining complex action/observation spaces suitable for RL algorithms. It handles data windows, feature extraction, and reward calculation.

Quick Start & Requirements

  • Install via pip: pip install gym-mtsim
  • Requires MetaTrader 5 software installed and a demo account.
  • Data download (download_data) is Windows-only due to the MetaTrader5 package dependency.
  • For examples: pip install stable-baselines3

Highlighted Details

  • Supports Forex, Stocks, and Crypto trading with both hedged and unhedged account modes.
  • Offers detailed visualization options for backtesting results (human, simple_figure, advanced_figure).
  • Customizes fees, symbol maximum orders, and multiprocessing for flexibility.
  • Provides a complex, flattened action space for RL agents to manage multiple orders per symbol.

Maintenance & Community

  • Developed by AminHP.
  • Links to official documentation and examples are available within the README.

Licensing & Compatibility

  • The project appears to be under the MIT license, allowing for commercial use and integration with closed-source projects.

Limitations & Caveats

  • The download_data functionality is restricted to Windows due to the MetaTrader5 Python package.
  • The action space is a flattened representation, requiring careful handling within RL frameworks to map back to specific trading actions (e.g., closing orders, placing new orders with volume).
Health Check
Last commit

8 months ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
14 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.