This Python script facilitates copy trading between two MetaTrader 5 accounts. Any trade placed on account 1 will be automatically copied to account 2. Similarly, when a trade is closed on account 1, it will also be closed on account 2.
Please be aware that this script does not guarantee the successful execution of copied trades. You must test it thoroughly with a demo account before using it on a live account. I am not responsible for any potential losses or damages resulting from the use of this script.
- Trade Mirroring: Automatically copies trades from account 1 to account 2.
- Selective Trade Copying: Trades are only copied if both stop loss and take profit are set.
- Real-time Synchronization: Trades are mirrored in real-time, ensuring that account 2 reflects the actions taken on account 1.
- MetaTrader 5 installed
- In MetaTrader 5 => Options => Expert Advisors, only Allow algorithmic trading and Allow DLL imports should be checked!
- Download and install Python from the official website.
- Add Python to your system PATH during the installation.
- Install Python using your distribution's package manager. For example, on Ubuntu:
sudo apt update sudo apt install python3 python3-pip
- Download and install Python from the official website.
- Alternatively, you can use Homebrew:
brew install python
- Install MetaTrader 5:
pip install MetaTrader5
- Uninstall numpy and install a compatible version:
pip uninstall numpy pip install numpy==1.26.4
- After the first execution of the script, fill in the
accounts.json
file with the credentials of both MetaTrader 5 accounts:{ "account_1": { "login": "your_login", "password": "your_password", "server": "your_server" }, "account_2": { "login": "your_login", "password": "your_password", "server": "your_server" } }
- Save the
accounts.json
file.
- Run the script:
python CopyTrading.py
- The script will start monitoring trades on account 1 and copy them to account 2, provided that stop loss and take profit are set.
- Only trades placed after starting the script will be copied. Existing trades will not be mirrored.
- Trades without stop loss and take profit will not be copied.
- Stop Loss and Take Profit Synchronization: Automatically synchronize any changes in stop loss and take profit for copied trades.
- MetaTrader 5
- Python Community
For any issues or suggestions, feel free to open an issue or contact the maintainers.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.