MT5-Python-Trading is a project that enables algorithmic trading with MetaTrader 5 using Python. This repository provides tools and scripts to automate trading strategies, manage positions, and analyze historical data.
This project aims to simplify algorithmic trading on MetaTrader 5 by leveraging the power of Python. It includes modules for opening/closing positions, retrieving historical data, and implementing various trading strategies.
- Automated Trading: Execute trading strategies automatically.
- Position Management: Open, close, and manage trading positions.
- Historical Data Analysis: Retrieve and analyze historical trading data.
- Break-Even Adjustment: Automatically adjust stop-loss to break-even.
- MetaTrader 5 terminal installed on your machine.
- Python 3.12 or higher.
- uv package manager.
-
Clone the repository:
git clone https://github.com/ntungufhadzeni/MT5-Python-Trading.git cd MT5-Python-Trading -
Create virtual environment and install dependencies:
# Install uv if you haven't already powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # Create and activate virtual environment with Python 3.12 and install dependencies uv sync .venv\Scripts\activate
-
Open your MetaTrader 5 terminal and ensure it is connected to your trading account.
-
Configure the .env file with your MetaTrader 5 login details.
SERVER=<your MT5 server> LOGIN=<your MT5 account number> PASSWORD=<your password>
-
Explore the provided examples and adapt them to your trading strategy.
- Run the Python scripts to execute your trading strategies.
python demo_trading.py
- Customize the provided scripts or create your own based on the requirements.
- Refer to the documentation for detailed information on each module.
MT5-Python-Trading/
├── mt5_trading/
│ ├── domain/
│ ├── robot/
│ └── logging_config.py
├── demo_trading.py
├── live_trading.py
├── .env
├── pyproject.toml
└── README.md
- Ensure MetaTrader 5 terminal is running before executing the scripts.
- Ensure that Algo Trading is enabled in your MetaTrader 5 account.
- Configure your trading parameters in the entry point files before running.
- All trades are executed based on the defined strategy logic.