Skip to main content

Installation

  1. Create a virtual env to avoid issues between versions using python -m venv name_env
  2. Activate virtual env and run pip install atlas-algo-trading
  3. Go to the examples section and modify the .env file with your own data to start interacting with MT5.

Note: You need to have a terminal of Metatrader 5 in your computer to work.

Introduction

This module use the Metatatrader5 library to connect with the platform, the functions were adapted to launch operations with own parameters and conditions.To know more information about the functions of Metatrade 5, please refer the next documentation:
https://www.mql5.com/en/docs/integration/python_metatrader5

Next you can read more about each function and how to implement it.

MT5

This class is a wrapper for the MT5 library that contains all related methods to interact with Metatrader 5 such as:

  • Create Connection
  • Retrieve data
  • Open Trades
  • Close Trades
  • Get Account Info
  • Constructor Method

    Create an object to enable the connection with MT5

    Parameters

    1. User (int) --> Account Id
    2. Password (str) --> Password of the Account
    3. Server (str) --> Server of the Account

    Example:

    user = 12345
    password = "passwd123"
    server = "MetaQuotes-Demo"
    conn = MT5(user,password,server)
    

    Note: By default the contructor method call the start method to start the connection to the MT5 server which will open the terminal of MT5.

    start()

    Create a connection to the Metatrader 5 server.

    Example:

    conn.start()
    

    close()

    Close the connection to Metatrader5 server.

    Example:

    conn.close()
    

    account_details(show=0)

    Return an object of type AccountInfo from Metatrader 5 library that contains all the information related to the account.

    Note: If you want to print the info pass 1 as and argument.

    Example:

    # Display object with attributes
    conn.account_details(1)
    

    # Save balance into a variable
    balance = conn.account_details().balance
    

    display_symbols(keyword,spread=30)

    Parameters

    1. keyword (list) --> Keywords to match the symbols.
    2. spread (int) --> Maximum value of spread of the symbols.

    The method will return a DataFrame with most relevant data of the symbols that satisfy the criteria..

    Example:

    # Filter the symbols that contains "EUR" or "USD" and the spread value is less than 30
    symbols = conn.display_symbols(["EUR","USD"],30)    
    

    open_position(symbol,operation,lot,points=40,comment="Python")

    Parameters

    1. symbol (str) --> Name of the symbol exactly as in the broker appears
    2. operation (int) --> BUY(1) / SELL(0)
    3. lot (int) --> Size of the operation to open
    4. points (int) or (list)
      • a) Number of points to set the SL and TP from the entry price. This will follow 1:1 ratio.
        b) [SL,TP] a list with the specific values of the price where the SL and TP should be set.
    5. comment: Comment displayed in the MT5 console.

    This method create and send a request to execute the position with the input parameters.

    Note: Use the display_symbols() to retrive the right name of the symbol.

    Example:

    SELL 0.2 lots in EURUSD with 40 points as SL/TP

    order_id = conn.open_position("EURUSD",0,0.2,40,"This trade was executed from my code")    
    

    get_positions(symbol=None)

    Parameters

    1. symbol (str) --> Get trades info exclusively of the symbol passed

    Returns a pandas dataframe with trades open if exists.

    Example:

    df = conn.get_positions()   
    

    close_position(ticket, comment="Close", display=False)

    Parameters

    1. ticket (int) --> Ticket number of the trade to close
    2. comment (str) --> Comment to add to the order.

    This method create and send the request to close the position with passed args.

    Examples:

    ticket_id = 12345
    
    conn.close_position(ticket_id,"Trade closed from my code")  
    

    get_data(symbol, temp, n_periods, plot=0)

    Parameters

    1. symbo (str) --> Name of the symbol
    2. temp (str) --> TimeFrame to get data (M1,M3,H1, etc)
    3. n_periods (int) --> Number of bars to get from current time (Current time - n_periods)
    4. plot (int) --> Display a chart in japanese format
        1 - Plot the DataFrame
        0 - Only returns the DataFrame (default)

    Example:

    Return a dataFrame with the last 100 min and plot it.

    data_from_n_periods = MT5.get_data("EURUSD","M1",100,1)      
    

    To check the correct timeframes print the next code:

    print(MT5.timeframes)
    

    In this example the name of the stock was manually passed, remember use the aproppiate method to extract the name exactly as the broker to avoid errors.

    calculate_profit(symbol,points,lot,order)

    Parameters

    1. symbol:Name of the symbol --> str
    2. points: Number of points to calculate the profit/loss --> int
    3. lots: Size of the simulated trade --> float/int
    4. order: BUY (1) or SELL (0) --> int

    This method allow you to calculte the profit or loss without need to open trades.

    Examples

    Profit from a trade in EURUSD symbol

    profit = MT5.calculate_profit("EURUSD",40,0.1,0)
    

    Metadata

    Release files for atlas-algo-trading 1.0.6

    For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

    Source distribution (sdist)

    Source distribution for atlas-algo-trading 1.0.6
    File Size Uploaded Provenance Actions
    atlas_algo_trading-1.0.6.tar.gz 10.6 kB Without provenance Details for atlas_algo_trading-1.0.6.tar.gz

    Built distribution (wheel)

    Table of built distributions (wheels) for atlas-algo-trading 1.0.6
    File Interpreter ABI Platform Actions
    atlas_algo_trading-1.0.6-py3-none-any.whl Python 3 none any Details for atlas_algo_trading-1.0.6-py3-none-any.whl

    Total release size: 19.6 kB

    Release files / atlas_algo_trading-1.0.6.tar.gz

    Download URL atlas_algo_trading-1.0.6.tar.gz
    Size 10.6 kB
    Tags Source
    SHA-256 checksum
    How to use checksums
    1147513de211ebe164f4fe0e6b56a57c9576498dc4cdbda9503af8ed1ca18384
    BLAKE2b-256 checksum
    How to use checksums
    15259b517f8db4f769c4128a533334b19d22e1205a8244226c0a09120412e577
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/6.1.0 CPython/3.9.9

    Release files / atlas_algo_trading-1.0.6-py3-none-any.whl

    Download URL atlas_algo_trading-1.0.6-py3-none-any.whl
    Size 9.0 kB
    Tags Python 3
    SHA-256 checksum
    How to use checksums
    af4188858c0b8b4e4a35d51899e438bbf82babcb7b348287b44a9c97c038e0a3
    BLAKE2b-256 checksum
    How to use checksums
    3af09ef9ac5c2e8789d88ba5c1c161debae4b4d04f648dff81e09d089df3a101
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/6.1.0 CPython/3.9.9

    Security for atlas-algo-trading 1.0.6

    Provenance

    Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

    No provenance found

    None of the files in this release were uploaded with provenance metadata.

    A note on package security

    PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

    To learn more about protecting yourself from malicious actors, visit our package security documentation.

    Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page