Skip to main content

A Python-based MetaTrader strategy tester for the MetaTrader5 module

Project description


title: StrategyTester5 (introduction) description: Getting started with the StrategyTester5 using MetaTrader5 in Python. keywords: StrategyTester5 home, MetaTrader5 Python, MT5 Python trading bot, install trading bot framework, algorithmic trading Python MT5

hide: - navigation

What is StrategyTester5?

StrategyTester5 (ST5) is a Python framework for building, testing, and optimizing algorithmic trading strategies using the MetaTrader 5 platform.

It extends the native MetaTrader 5 Python API by adding high-performance backtesting, simulation, and data handling capabilities that are not available out of the box.

"banner"

Why StrategyTester5?

The official MetaTrader5 Python API provides access to market data and trading operations — but it lacks a built-in way to efficiently backtest and simulate trading strategies.

StrategyTester5 fills this gap by providing backtesting and optimization capabilities.

!!! Note "Note"

Built for developers who want full control over their trading logic without leaving the MetaTrader 5 ecosystem.

How it Works

It simulates the MetaTrader5 API on the actual historical data from the MetaTrader5 terminal. See a quick start guide.

Installation

With pip (recommended)

This package is available at Python package index pypi.org.

pip install strategytester5

Or, you can install while checking for the updates.

pip install -U strategytester5

With git

Of course, you can pull strategytester5 directly from the GitHub repository.

Git clone:

git clone git@github.com:MegaJoctan/StrategyTester5.git strategytester5

Install the cloned repository as a package:

pip install -e strategytester5

Quick Start | Build & Test your First Trading Robot

All you need is to add three (3) Lines of code to your existing Python project.

01: Import the VirtualMetaTrader5 class

from strategytester5.MetaTrader5.api import VirtualMetaTrader5

02: Assign the parent (MetaTrader5) initialized instance to the VirtulMetaTrader5 object

if not mt5.initialize():
    raise RuntimeError(f"Failed to initialize mt5. Error = {mt5.last_error()}")

virtual_mt5 = VirtualMetaTrader5(parent_mt5=mt5)

Optional : Choosing the right MT5 instance

Since the VirtualMetaTrader5 object has similar methods and constants to MetaTrader5 API.

To keep all the code in a single file, introduce if statements to check for passed arguments from the script.

!!! Note "Rule of Thumb"

For instance, if a user has passed `--backtesting` when calling the main script the script should use a simulated MetaTrader5 rather than the actual one.

```python
script_argument = sys.argv[1:]
if "--backtesting" in script_argument:
    mt5 = VirtualMetaTrader5(parent_mt5=parent_mt5) # Assign parent MetaTrader5 to the virtual MetaTrader5 class object
else:
    mt5 = parent_mt5
```

> Always use the virtual MetaTrader5 object for backtesting and visualization purposes and stick to the original one for live trading. *That's all*

03: Backtesting your Python Trading Strategies

To Backtest your trading systems call the function run_backtesting.

if "--backtesting" in script_argument:

    stats = run_backtesting(
        main_function=main,
        tester_config=tester_config,
        virtual_mt5=mt5,
        logging_level=logging.DEBUG
    )

else:
    # run the script on the market (realtime)
    while True:
        main()

Tester Configurations

The so-called tester_config is supposed to be a dictionary with a set of key, and value pairs that resemble MetaTrader5's strategy tester section.

mt5config

tester_config = {
        "bot_name": "RSI Strategy Bot",
        "symbols": ["EURUSD"],
        "timeframe": "H1",
        "start_date": "01.01.2026",
        "end_date": "01.06.2026",
        "modelling" : "open price only",
        "deposit": 1000,
        "leverage": "1:100"
}

Learn More.

!!! Note "Rule of Thumb"

Storing tester configuration in a JSON file is the best way forward. It helps adjust the values without changing the original code :)

Backtest your Python bots in MetaTrader5 👉 Learn How

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strategytester5-2.2.5.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strategytester5-2.2.5-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file strategytester5-2.2.5.tar.gz.

File metadata

  • Download URL: strategytester5-2.2.5.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for strategytester5-2.2.5.tar.gz
Algorithm Hash digest
SHA256 58156cb72e226722f9edf2953ada3c4df45a6d27f7bd377db2e177b4115b3b98
MD5 f4b6740ea3b32f659601632af5cf311c
BLAKE2b-256 5f2077dd7dfb99f26888bb075eec4cb66a4c2cab886e8739d6da338340f338c2

See more details on using hashes here.

File details

Details for the file strategytester5-2.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for strategytester5-2.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f996e9c2999b4e41dc097eb39e24500310acd3f66491ce4075933b043f5b8b37
MD5 0adf47f258e14145fd8a7d7b27027390
BLAKE2b-256 1a4b3986738116b1957bc0eed8cf68a3d0455028f924b84d6c49aa48ef05364e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page