Discussion of article "MetaTrader 5 and Python integration: receiving and sending data" - page 6

 
Maxim Dmitrievsky:

Hi all

Note

Connection address should be added to the list of allowed ones on the client terminal side (Tools \ Options \ Expert Advisors).

If connection fails, error 5272 (ERR_NETSOCKET_CANNOT_CONNECT) is written to_LastError.

The function can be called only from Expert Advisors and scripts, as they run in their own execution threads. If calling from an indicator,GetLastError() returns the error 4014 - "Function is not allowed for call".



https://www.mql5.com/en/docs/network/socketconnect


Hi Maxim Dmitrievsky,

I allowed the localhost and it's working correctly.Thank you very much! But when I ran in backtest using the Strategy Tester, the error 4014 persisted. The socket doesn't work with backtest?

Best regards
[Deleted]  
auuuuu1628:

Hi Maxim Dmitrievsky,

I allowed the localhost and it's working correctly.Thank you very much! But when I ran in backtest using the Strategy Tester, the error 4014 persisted. The socket doesn't work with backtest?

Best regards

Yes, all right. Metaquotes disabled this feature in backtester, but they say maybe allow this in near future.

 

Why not close "xxx" immediately after receiving a response from the server, instead of continuing to wait for the response until it reaches TimeOut?

I'm referring to the amazing programme developed by @MaximDmitrievsky -> https://www.mql5.com/en/articles/5691

(( The socketreceive() function listens on a port, and returns it as a string when there is a response from the server: ))

string socketreceive(int sock, int timeout) {
        char rsp[];
        string result = "";
        uint len;
        uint timeout_check=GetTickCount()+timeout;
        do {
                len=SocketIsReadable(sock); 
                if(len){
                        int rsp_len;
                        rsp_len = SocketRead(sock,rsp,len,timeout);
                        if(rsp_len>0){
                                result+=CharArrayToString(rsp,0,rsp_len); 
                        }
                }
        } while((GetTickCount()<timeout_check) && !IsStopped());
        return result;
}

Congratulations on this great article.

Maxim Dmitrievsky
Maxim Dmitrievsky
  • www.mql5.com
Опубликовал статью Грокаем "память" рынка через дифференцирование и энтропийный анализ Область применения дробного дифференцирования достаточно широка. Например, алгоритмы машинного обучения, обычно, принимают дифференцированный ряд на вход. Проблема в том, что необходимо вывести новые данные в...
 
Hi!
I was wondering to know how can i keep getting live data from mql5 and append it to my list or my dataframe
At the moment a touple comes out of metatrader commands and converts to a dataframe, but what if we want to keep getting the data and at to the dataframe
Tnx maxim, you have been a great help
 

Good morning, I'm getting a dll error

Traceback (most recent call last):

File "teste_conexao.py", line 2, in <module>
from MetaTrader5 import *
File "C:\Users\anton\AppData\Local\Programs\Python\Python37\lib\site-packages\MetaTrader5\__init__.py", line 35, in <module>
from .C import *

ImportError: DLL load failed: The specified module could not be found.


Does anyone know what I'm doing wrong?

 

<Deleted>

This is an English language forum. Please only post in English.

 

Hi,

Could someone write an example code how to open a 'Buy' or 'Sell' position from Python and also how to close that postition?

Or maybe is that not possible?

Many thanks!

 
Antonio Batista:

Good morning, I'm getting a dll error

Traceback (most recent call last):

File "teste_conexao.py", line 2, in <module>
from MetaTrader5 import *
File "C:\Users\anton\AppData\Local\Programs\Python\Python37\lib\site-packages\MetaTrader5\__init__.py", line 35, in <module>
from .C import *

ImportError: DLL load failed: The specified module could not be found.


Does anyone know what I'm doing wrong?

Hello Antonio,

this error usually happens when you try to install the library on a Python that isn't Python for Windows. Try installing https://www.python.org/downloads/ and see if it corrects the error.


Cheers

Download Python
Download Python
  • www.python.org
The official home of the Python Programming Language
 

MetaTrader5 module does not work

import MetaTrader5 as mt5 works like this

but when from MetaTrader5 import * (I connect it completely it goes out in Pycharme).

Can anyone tell me what the problem is?????

 

how to connect a metatrader5 indicator to python.


Thanks