Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

MetaTrader4 Libraries easily backtest and optimization from python

Project Description

py-metatrader 0.0.1

Released: 30-May-2015


py-metatrader is a python package that provides interfaces to metatrader4(mt4). metatrader4 is a trading platform that can automate trading(fx, stock, etc…) by your own program(ExpertAdvisor in mt4).

you can automate simuration(backtest in mt4), CI EA development , etc… by using this library.

currently works with Python 2.7.

contributing and porting is welcome.


At the moment, py-metatrader supports:

  • backtest
  • optimization

The goal of py-metatrader is to support execute all feature of metatrader4 from this library.


Install via pip:

$ pip install metatrader

Install from source:

$ git clone
$ cd py-metatrader
$ python install


  • 0.0.1
    • first release. backtest and optimization from python.



from metatrader.mt4 import initizalize
from metatrader.backtest import BackTest

# point mt4 install folder
initizalize('C:\\Program Files\\FXCM MetaTrader 4')

# specify backtest period by datetime format
from_date = datetime(2014, 9, 1)
to_date = datetime(2015, 1, 1)

ea_name = 'Moving Average'

# create ea param by dict.
param = {
         'Lots': {'value': 0.1},
         'MaximumRisk': {'value': 0.02},
         'DecreaseFactor': {'value': 3.0},
         'MovingPeriod': {'value': 12},
         'MovingShift': {'value': 6}
# create backtest object
backtest = BackTest(ea_name, param, 'USDJPY', 'M5', from_date, to_date)

# run backtest
ret =

# you can get result from result object
# for example you can print gross profit
print ret.gross_profit
Release History

Release History

This version
History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date (11.2 kB) Copy SHA256 Checksum SHA256 Source May 28, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting