Giter Site home page Giter Site logo

thesnowguru / pytrader-python-mt4-mt5-trading-api-connector-drag-n-drop Goto Github PK

View Code? Open in Web Editor NEW
662.0 39.0 13.0 35.28 MB

Open Source Trading Strategies & End-to-End solution connecting Metatrader4 & Metatrader5 💹 with Python with a simple drag and drop EA. Fully tested bug free & efficient solution for live & paper trading⭐ Full Documentation ready. Lightweight, efficient and stable implementation 🔥

Home Page: https://discord.gg/wRMUNP8ERa

Python 100.00%
trading forex fx forex-trading metatrader mt5 mt5-api mt5script mt5-gateways mt5-platform

pytrader-python-mt4-mt5-trading-api-connector-drag-n-drop's Introduction

PyTrader - Drag & Drop MT4 & MT5 Python API Connector for Metatrader

PyTrader

The Pytrader ecosystem consists of a python script and a MT5 or MT4 EA. Further for the licensing an indicator is used. Documentation for connecting Metatrader 5 and metatrader 4 with Python using a simple drag and drop EA. A full suited solution and fully tested , fast and efficient.

The communication between the python script and the EA is based on websockets. EA is the Server and the python script the Client. It is always query(function / python script) and output(data / server). The EA does not need to run on same computer as the python script is running on. On our Github link you will find the python script, the EA’s, full documentation, and a Pytrader example script showing how to call the functions. For questions we have also a discord channel. In demo (without licensing indicator) also full functionality, but for a limited number of instruments (EURUSD, AUDCHF, NZDCHF, GBPNZD and USDCAD).

name

Check versions: Pytrader version _06 works with EA version .06.

Python MT4 & MT5 EA connecor

Easier more than ever before! Connecting Metatrader5 with Python strategies with this simple drag and drop EA has never been so easy! A full & fast solution tested with real trading. Amazing capabilities like download bar data & creating a live feed for your strategies with 1 line of code. Enjoy.

Drag & Drop Python Connector for MT4 & MT5

Growing list of features:

  • Python login to Metatrader5 Terminal
  • Python Connection keep alive function
  • Get MT5 Account Info→ Python client
  • Python Client Open New Orders → MT5 (Verify the sending, and verifying the receiving the order ,in MetaTrader5)
  • Python Client can Change(take profit,stop loss) /Cancel/Open Orders → MT5
  • Python Close/Partly Close Positions → MT5
  • MT5 Execution info→ Python client
  • MT5 → Python Get all Open orders & Positions
  • MT5 → Python Get static account information
  • MT5 → Python Get dynamic account info like [balance, equity, margin, free margins]
  • MT5 → Python Get instrument information [pip value, max lot, tick size, tick value]
  • MT5 → Python Get last tick data [date, bid, ask, vol ]
  • MT5 → Python Get bar data [date, open, low, high, close, vol]
  • MT5 → Python Get last X ticks array[date, bid, ask, last,vol]
  • MT5 → Python Get last X bars array[date, open, low, high, close, vol]
  • MT5 → Python Get indicator data from MT5 to your script - coming soon!

MT5 installation flow:

alt text

MT4 python

installation flow:

alt text

myLib documentation

See documentation MT5 here See documentation MT4 here

Linux installation:

You can run your strategies on linux through wine.
Here is a ready docker + Wine: here

Get the EA working for all instruments:

MT5 python ==> Get FULL Version here

MT4 python ==> Get FULL Version here

pytrader-python-mt4-mt5-trading-api-connector-drag-n-drop's People

Contributors

branly76 avatar minhphuc429 avatar thesnowguru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytrader-python-mt4-mt5-trading-api-connector-drag-n-drop's Issues

Open order issue

I get this error when I try to open a new order using the library demo version:
order_error : 0
order_return_message : Trading not allowed

Couldnt connect with the socket-server

Hi,
I get the following order when trying to open a connection:
Couldnt connect with the socket-server: [WinError 10061] No connection could be made because the target machine actively refused itelf.sock

I tryed different ports without success. The EA is attached to the chart because if a right click on it i see Pytrader context menù but I don't see icons over the chart (I used to see the EA version with the smile in the upper right corner and the licensed info with the port number in the upper left corner).

issue with license

Hello Sir
email : [email protected]

i try the Pytrader demo was very good and fast and then i bought license Order number 230928_**96 today and MT4 install Pytrader mt4 Python 2.06 as indicator not EA, there is no place to input the Authorization code and cannot connect with it same socket port 1110
so in conclusion the installed indicator Pytrader mt4 Python 2.06 is not working at all , no place to put Authorization code and couldn't connect with

also another question mentioned 5 activation based on machine or MT4 account if so (include demo MT4 account?)

your feed back is highly appreciated

MT4 Unhandled exception 0xE0434352, Pytrader_MT4_EA_V1.02 EURUSD,M1: not initialized, Pytrader_MT4_EA_V1.02 EURUSD,M1: uninit reason 8

Everytime i try to add the ea to the chart i receive the following

2020.11.20 12:29:05.318 Expert Pytrader_MT4_EA_V1.02 EURUSD,M1: removed
2020.11.20 12:29:05.318 Pytrader_MT4_EA_V1.02 EURUSD,M1: uninit reason 8
2020.11.20 12:29:05.318 Pytrader_MT4_EA_V1.02 EURUSD,M1: not initialized
2020.11.20 12:29:05.318 Unhandled exception 0xE0434352
2020.11.20 12:29:04.646 Pytrader_MT4_EA_V1.02 EURUSD,M1: Server socket created
2020.11.20 12:29:04.474 Pytrader_MT4_EA_V1.02 EURUSD,M1 inputs: ServerPort=22222; key=; activation_key=;
2020.11.20 12:28:59.162 Expert Pytrader_MT4_EA_V1.02 EURUSD,M1: loaded successfully

I have add .net 3.5 as well as installed Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019. I am running this on server 2019, what am I missing?

thanks!

Examples of live streaming data

Hi there,
Thank you for your effort to make such a perfect API.
Can someone please give me some examples of getting live-streamed data with the following functions:

1 - Get_last_tick_info()
2 - Get_actual_bar_info()

These functions can be used for live streaming data as mentioned in the project document.

There are some good examples of using this API in the Python_script_example_PyTrader.py file, but no example of using it for live streaming.

best regards

Possible to run strategy in raspberry pi then execute trade in Windows 10?

Hi,

Is it possible to run the strategy from a raspberry pi then execute the trade order in Windows 10?

I tried to input the IP address of my Windows 10 computer and port used in the script being ran in the raspberry pi but I got error "BrokenPipeError: [Errno 32] Broken pipe".

Anything I can do to make this work?

Suggest to use pandas capabilities

First of all, thanks for your effort.
I'd like to suggest using of pandas data reading capabilities rather than using loops.
What do you think of something like this?
Cheers

--

import io

TZ_SERVER = 'Europe/Tallinn' # EET
TZ_LOCAL  = 'Europe/Budapest'
TZ_UTC    = 'UTC'

# get all open positions
ok, resp = MT.send_command("F061#0#")
if ok==True and resp[0:5]=="F061#" and resp[-1]=="!":
    df = pd.read_table(io.StringIO(resp[resp.index('#',5)+1:-1]), sep='$', lineterminator='#',
                       header=None,
                       names=np.array(MT.columnsOpenPositions[1:])[:,0],
                       dtype=MT.columnsOpenPositions[1:]
    ).fillna('')
    df.open_time = pd.to_datetime(df.open_time, unit='s').dt.tz_localize(TZ_SERVER).dt.tz_convert(TZ_UTC)
else:
    pass

Limitation for get all closed positions

Has some limitations about the number of information you could request?

I only get 14 most recent pieces of information but have more than 30 records.

(Pdb) timezone = pytz.timezone("Etc/UTC")
(Pdb) self.connect().Get_all_closed_positions(date_from=datetime(2020, 3, 3, tzinfo=timezone), date_to=datetime.now())

    position_ticket instrument  order_ticket position_type  magic_number  volume  open_price   open_time  close_price    close_time        comment  profit  swap  commission
0         832580774     EURUSD     832580946          sell          2000    0.03     1.20699  1610953450      1.20700  1.610953e+09  Perucchi Inc    -0.03   0.0         0.0
1         832580780     EURUSD     832580986          sell          2000    0.02     1.20699  1610953451      1.20700  1.610953e+09  Perucchi Inc    -0.02   0.0         0.0
2         832580815     EURUSD     832581007          sell          2000    0.03     1.20699  1610953453      1.20700  1.610953e+09  Perucchi Inc    -0.03   0.0         0.0
3         832580820     EURUSD     832581032          sell          2000    0.02     1.20699  1610953453      1.20700  1.610953e+09  Perucchi Inc    -0.02   0.0         0.0
4         832580854     EURUSD     832581072          sell          2000    0.03     1.20699  1610953456      1.20700  1.610953e+09  Perucchi Inc    -0.03   0.0         0.0
5         832580860     EURUSD     832581075          sell          2000    0.02     1.20699  1610953456      1.20696  1.610953e+09  Perucchi Inc     0.06   0.0         0.0
6         832583189     EURUSD     832596730          sell          2000    0.03     1.20680  1610953645      1.20682  1.610955e+09  Perucchi Inc    -0.06   0.0         0.0
7         832583195     EURUSD     832596740          sell          2000    0.02     1.20680  1610953645      1.20683  1.610955e+09  Perucchi Inc    -0.06   0.0         0.0
8         832585809     EURUSD     832596763          sell          2000    0.03     1.20690  1610953838      1.20685  1.610955e+09  Perucchi Inc     0.15   0.0         0.0
9         832594901     EURUSD     832596781          sell          2000    0.03     1.20659  1610954452      1.20685  1.610955e+09  Perucchi Inc    -0.78   0.0         0.0
10        832595835     EURUSD     832596799          sell          2000    0.03     1.20673  1610954498      1.20685  1.610955e+09  Perucchi Inc    -0.36   0.0         0.0
11        832597571     EURUSD     833245634          sell          2000    0.02     1.20673  1610954609      1.20592  1.610983e+09  Perucchi Inc     1.62   0.0         0.0
12        832597566     EURUSD     833245647          sell          2000    0.03     1.20673  1610954608      1.20592  1.610983e+09  Perucchi Inc     2.43   0.0         0.0
13        833654586     EURUSD     833658133          sell          2000    0.03     1.20739  1611001925      1.20742  1.611002e+09  Perucchi Inc    -0.09   0.0         0.0
14        833654590     EURUSD     833658137          sell          2000    0.02     1.20739  1611001926      1.20742  1.611002e+09  Perucchi Inc    -0.06   0.0         0.0`

Suggest:

  • get information MetaTrader history by ticket (even open or closed)

can't connect to the mt5 server

my question

I'm trying to test the demo, but someting got wrong.
I've already open the dll load, and move the Pytrader_MT5_EA_V2.08.ex5 to script folder, set the params, and click the start, snapshot here

image

image

all seems fine, but when I'm trying to run the python client, the port is 1110 and server ip is 127.0.0.1, I found that the server seems like doesn't response, but the 1110 port is real listening
image

as my debug, I found the problem is self.send_command(self.command) the code doesn't got any real response, then the python script just stuck here, how to solve it?

image

image

also following is the test script
Python_script_example_PyTrader.txt

my env:

Python 3.7.7

MT5

image
image

thanks for response

SyntaxError: 'break' outside loop

On the V3_01a.py at

def send_command(self,
                 command):
    self.command = command + self.authorization_code + "^" "!"
    self.timeout = False

    try:
        self.sock.send(bytes(self.command, "utf-8"))
        data_received = ''
        try:
            data_received = data_received + self.sock.recv(500000).decode()
            if data_received.endswith('!'):
                break

On line 2088 I'm getting a SyntaxError: 'break' outside loop. Could you look into it please?

setting trailing stop

Hi,
is it possible to set trailing stop while sending order via mt5?
if no, is there another mechanism doing that automatically using Metatrader itself?
thanks

request to replay on issue 49

Dear Sir

kindly to replay on the issue 49 , need some guidance to connect with indicator
your help is much appreciated

Mt4 v2.06 version has import dll problem!

I had set allow import dll ,but it still tell me Alert: Allow DLL import ;
Did I set something wrong?

image

image

2021.04.23 14:40:48.417 Expert Pytrader_MT4_EA_V2.06 CADJPY+,H1: removed
2021.04.23 14:40:48.413 Pytrader_MT4_EA_V2.06 CADJPY+,H1: Server socket terminated
2021.04.23 14:40:48.413 Pytrader_MT4_EA_V2.06 CADJPY+,H1: uninit reason 8
2021.04.23 14:40:48.413 Pytrader_MT4_EA_V2.06 CADJPY+,H1: initialization failed (1)
2021.04.23 14:40:48.413 Pytrader_MT4_EA_V2.06 CADJPY+,H1: Alert: Allow DLL import.
2021.04.23 14:40:48.348 Pytrader_MT4_EA_V2.06 CADJPY+,H1 inputs: ServerPort=1122; location=Market\Pytrader mt4 Python;
2021.04.23 14:40:09.424 Expert Pytrader_MT4_EA_V2.06 CADJPY+,H1: loaded successfully

My OS Version:
image
My Mt4 platform:
image

Method Copy_rates_from issue

Hi there,

I would like to report an issue with a method.

I have used successfully run the following code with ticks:

# request 1000 ticks from EURAUD
euraud_ticks = mt5.copy_ticks_from("EURAUD", datetime(2020,1,28,13), 1000, mt5.COPY_TICKS_ALL)
# request ticks from AUDUSD within 2019.04.01 13:00 - 2019.04.02 13:00
audusd_ticks = mt5.copy_ticks_range("AUDUSD", datetime(2020,1,27,13), datetime(2020,1,28,13), mt5.COPY_TICKS_ALL)

But when I use this for :

eurusd_rates = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_H1, datetime(2020,1,28,13), 1000)

The same way is explained here:

https://www.mql5.com/en/docs/integration/python_metatrader5/mt5copyratesfrom_py

No matter what period, symbol, or timeframe, the object It returns is always "None" (not null).

Are you experiencing the same issue?

Thanks in advance

Python Strategy Script Error: No connection could be made because the target machine actively refused itelf.sock

C:\Users\Max\PyTrader-python-mt4-mt5-trading-api-connector-drag-n-drop\Strategies>python ma_cross_strategy.py
Start MT
Next...
Couldnt connect with the socket-server: [WinError 10061] No connection could be made because the target machine actively refused itelf.sock
 terminating program

C:\Users\Max\PyTrader-python-mt4-mt5-trading-api-connector-drag-n-drop\Strategies>python ma_cross_strategy.py
Start MT
Next...
Couldnt connect with the socket-server: [WinError 10061] No connection could be made because the target machine actively refused itelf.sock
 terminating program

C:\Users\Max\PyTrader-python-mt4-mt5-trading-api-connector-drag-n-drop\Strategies>python ma_cross_strategy.py
Start MT
Next...
Couldnt connect with the socket-server: [Errno 11001] getaddrinfo failedelf.sock
 terminating program

C:\Users\Max\PyTrader-python-mt4-mt5-trading-api-connector-drag-n-drop\Strategies>python ma_cross_strategy.py
Start MT
Next...
Couldnt connect with the socket-server: [WinError 10061] No connection could be made because the target machine actively refused itelf.sock
 terminating program

Source code:

# settings
timeframe = 'M1'
instrument = 'EURUSD'
# server_IP = '127.0.0.1'
# server_IP = 'locahost'
server_IP = '192.168.1.1'
server_port = 1122                                              # check port number
...

image

Experts setting:
image

Getting spread information on pair

Hi,

Is there a way to get the current spread on a pair?

How about historical spread?

I checked documentation and instrument info does not have it.

Thanks!

Demo mode - port not being opened for connection from python script MT4

Hey everyone,

I'm testing before I buy. In the demo, I'm testing with port 1122. I've disabled my firewalls and av software and it doesn't look like port 1122 is being opened for me to connect to. I've tried other ports as well. Am I missing something?

I've tried with both MT4 EA versions 2.03 and 2.05 and made sure the dll imports are allowed

Pytrader_API, function Get_broker_server_time()

Trying to use above Get_broker_server_time() function to retrieve broker server time yields an error as seen in the image below:

image

Pytrader_API Version: Pytrader_API_V2_081
OS Version: Win10 Pro
Editor: VSCode

Note that with Pytrader_API Version: Pytrader_API_V1_06a the Get_broker_server_time() function worked as expected.

Update software versions.

@TheSnowGuru

The following files need to be seen as actual versiobs.

Pytrader_MT5_EA_V2.081a.ex5, Pytrader_MT5_EA_V2.081b.ex5, Pytrader_MT4_EA_V3.01a.ex4, Pytrader_MT4_EA_V3.01b.ex4, Pytrader_API_V2.081a.py, Pytrader_API_V3.01a.py

All others move to the folder Older versions

BR

issues with get specific bar function and last Ticks

Dear Developer hope you are doing well

the below issues after test connection in real account not licensed EA yet just test if ok, so 3 issues as bellow
your help is highly appreciated

number 1:
number 1using the PyTrader_API_V3_01a.py

in line 2088 break

syntax Error:'break' outside loop

i switch to PyTrader_API_V3_1.py

number 2:

get specific_bar

                            Pytrader_API_V3_1.py", line 967, in Get_specific_bar
self.command = self.command + _instr + '$'
               ~~~~~~~~~~~~~^~~~~~~~

TypeError: can only concatenate str (not "NoneType") to str

NB: i changed the instrument_list to only EURUSD same type Error

instrument_list = 'EURUSD'

number 3:
last Ticks test function event for one tick

F998^2^NOK^02103^!

18
Empty DataFrame
Columns: []
Index: []


for last Bars function is working no issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.