darwinex / dwx-zeromq-connector

Wrapper library for algorithmic trading in Python 3, providing DMA/STP access to Darwinex liquidity via a ZeroMQ-enabled MetaTrader Bridge EA.
https://blog.darwinex.com/zeromq-interface-python-r-metatrader4/
BSD 3-Clause "New" or "Revised" License
342 stars 227 forks source link

Array out of range in DWX_ZeroMQ_Server_v2.0.1_RC8.mq4 #49

Open Saruntaey opened 4 years ago

Saruntaey commented 4 years ago

I have been modified DWX_ZeroMQ_Server_v2.0.1_RC8.mq4 to be able to perform my strategy. My workflow as per below.

  1. The EA keep track on market. when something interesting occor it will execute python script.
  2. Python script connect to the same ports as setup in EA. then request the opened orders detail.
  3. Python script perform some task. then request the opened orders detail again to modify orders.
  4. After the order was modified the python script is terminated.
  5. The EA keep tracking the market again.

The problem is the EA may get request from somewhere ( default ports was used ). I don't know how. So these break the code as per attatched picture below.

err_msg code

I am sure that this request didn't come from python script because EA status inform that it didn't execute the python script.

My question is :

  1. How this occur? and how to handle?
  2. When the EA get error as attatched picture, is it keep working or terminated?
integracore2 commented 4 years ago

Hi @Saruntaey ,

Sounds like you either have more than one instance of a client application running on your system, connecting to the same EA, or some other process also attempting to connect to the same ports sending instructions.

Please provide both the modified Python and MQL source code files as attachments, it isn't possible to assist with this query based on images unfortunately.

Thanks!

Saruntaey commented 4 years ago

@integracore2 Thank you for your responds. Pleases find my code as per attatched files. The upload only included MT4 connect module. How can I check if other process connect to the same ports as assigned. Is there are any method to find the free ports to use for communication between MQL and Python? If not how to handle this?

python.zip DWX_ZeroMQ_Server_v2.0.1_RC8_Modified_V5.zip

My code set up is per below.

  1. I have 2 MT4 accounts runing on seprate terminal.
  2. Attatch DWX_ZeroMQ_Server_v2.0.1_RC8_Modified_V5.mq4 to each MT4 therminal. The only different set up is ports number.

Thank you.

donggiggedin commented 3 years ago

I'm having the same problem, I don't know why this could happened. So weird.

brenoperucchi commented 3 years ago

Does anyone found a solution to this problem?

vsp4 commented 3 years ago

I faced a similar problem. This halts expert advisor until mt4 is manually restarted.

This issue is reproducible when a null message is received on ZeroMQ Socket.

Adding this check just before line 311 should fix this:

   if (ArraySize(compArray) == 0) {
      return;
   }

Its not exactly clear to me which program is sending such message as i don't see anything related to null sending within Python code, my guess would be this could be due to a botnet scan on the default open port 32768. Also, noticed that default Hostname is binded to *, As there is no authentication, setting HOSTNAME = 127.0.0.1 in parameters should be more secure (by not being open to internet) imo to avoid similar issue.

brenoperucchi commented 3 years ago

@vsp4 Thanks, I will try.