Skip to main content

A Python-based MetaTrader strategy tester for the MetaTrader5 module

Project description

What is StrategyTester5?

Full documentation -> https://strategytester5.com

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.6.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.6-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for strategytester5-2.2.6.tar.gz
Algorithm Hash digest
SHA256 965b24cc6089872a231776c31c556680d544a81d9b9e0e09ae8b45f2b5f9e808
MD5 b91e3510570e680ae1f0f6ab9d7a94e6
BLAKE2b-256 0e6967722b4c95e001c0c04d4919d13e6092ed5dec295dc35feee67af29736aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for strategytester5-2.2.6.tar.gz:

Publisher: python-publish.yml on MegaJoctan/StrategyTester5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for strategytester5-2.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 da98aaf6a609babda56afecadd1b43ecfe909f4d175e4fab744d50674f570dc7
MD5 125851d6dabf7eb40da5d490b3f08405
BLAKE2b-256 4f68508a444608e398da8bdbec4f0ec81ea7d6b48df9783319ad3c452ec72cb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for strategytester5-2.2.6-py3-none-any.whl:

Publisher: python-publish.yml on MegaJoctan/StrategyTester5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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