MetaTrader 5 Python User Group - the summary - page 24

Vladimir Karputov
Moderator
270428
Mike Oregon :

***

i.e: mt5.Close(symbol='GBPJPY', ticket = 233458963)

***

Where did you see such a team? Is there such a command in the help?

Mike Oregon
14
Mike Oregon  
Vladimir Karputov:

Where did you see such a team? Is there such a command in the help?

There is no such command in the help, but the function is available in the python MetaTrader5 module, and this it suggested in a stackoverflow solution I found

Mike Oregon
14
Mike Oregon  

Hello guys,

Can anyone here explain the general procedure for building mt5 python scripts

(ea's that are attached to the chart) by this I mean, provide answers to questions like:

1. How to make it possible for the script to be attached to a chart (apparently not all scripts can be attached)
2. How to make scripts that work on multiple pairs at the same time?
3. How to make a script automatically work with chart (symbol) its attached to?
4. Does the script (when attached to a chart) automatically work on each tick?

I've built a script, however I'm stuck on how to get it continuously running (accessing tick prices continuously), 

all my functions currently take in one parameter (the symbol) everything else is calculated on tick.


A simple EA example that can be attached to a chart would be great for new users to build upon.

Laurent Soudron
3691
Laurent Soudron  
Mike Oregon:

Hello guys,

Can anyone here explain the general procedure for building mt5 python scripts

(ea's that are attached to the chart) by this I mean, provide answers to questions like:

1. How to make it possible for the script to be attached to a chart (apparently not all scripts can be attached)
2. How to make scripts that work on multiple pairs at the same time?
3. How to make a script automatically work with chart (symbol) its attached to?
4. Does the script (when attached to a chart) automatically work on each tick?

I've built a script, however I'm stuck on how to get it continuously running (accessing tick prices continuously), 

all my functions currently take in one parameter (the symbol) everything else is calculated on tick.


A simple EA example that can be attached to a chart would be great for new users to build upon.

Hi Mike,

It doesn't work at all like a classic EA.

Your Python script runs independently (like any other Python script) in its own environment and it drives the MetaTrader program (like an API or a DLL).

So you don't have to attach your script to a chart like you would with a classic EA.

You don't have to do anything special to be able to open positions on several different pairs, you just have to specify different symbols when you call the order_send function.

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

As your Python script is not attached to a chart, and it runs outside the MetaTrader environment, you do not have the OnTick(), OnTimer().... events. 

It is up to you to integrate in your Python program a loop with the equivalent of a timer to test the price changes and trigger the actions you need afterwards.

I hope that these explanations will help you to see things more clearly.

Mike Oregon
14
Mike Oregon  
Laurent Soudron:

Hi Mike,

It doesn't work at all like a classic EA.

Your Python script runs independently ....


Thanks Laurent,

You are right about the above, I also did some digging and found a few things out.

To 'attach' the script to a chart, one needs to run the main code in an infinite loop.

It is possible to get the symbol and timeframe the script is attached to by importing sys and using sys.argv[1], sys.argv[2]

(based on nicolishen's post at page 16 or 17)


However it seems to have a bug. Only the timeframe values are updated when script is attached to different charts.

I don't know where to report this bug though

Files:
nzdchf_eg.jpg  221 kb
Laurent Soudron
3691
Laurent Soudron  
Mike Oregon:

Thanks Laurent,

You are right about the above, I also did some digging and found a few things out.

To 'attach' the script to a chart, one needs to run the main code in an infinite loop.

It is possible to get the symbol and timeframe the script is attached to by importing sys and using sys.argv[1], sys.argv[2]

(based on nicolishen's post at page 16 or 17)


However it seems to have a bug. Only the timeframe values are updated when script is attached to different charts.

I don't know where to report this bug though

Yes, it works too, but to do the development and the adjustments, it's much easier to use a specialized Python environment like PyCharm, Visual Studio Code... in order to take advantage of all the features like refactoring, code completion...

And once the program is finished, integrate it into MT5 to test it on a demo account or in production with a real account.

Personally, I prefer to manage the symbol and the timeframe(s) in the script rather than retrieving those from the graph. This avoids errors if you change the timeframe on the graph, for example.

Can you put a code example here in the forum, to reproduce your bug? That way the MetaQuotes team can have a look too.

chrisduplessis
5
chrisduplessis  

Hello,

I would like some clarification on the following error I am running into when trying to attach a python script to a chart in MT5.

I create the python script in MetaEditor, a basic 'Hello World' script & the compile succeeds.

When I try to attach the script to a chart in the MT5 main terminal I run into the following error: (PNG attached below)

Thanks in advance.

Files:
Capture2.PNG  11 kb
Laurent Soudron
3691
Laurent Soudron  
chrisduplessis :

Hello,

I would like some clarification on the following error I am running into when trying to attach a python script to a chart in MT5.

I create the python script in MetaEditor, a basic 'Hello World' script & the compile succeeds.

When I try to attach the script to a chart in the MT5 main terminal I run into the following error: (PNG attached below)

Thanks in advance.

Python 3.8 is well installed on your computer?

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

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Rez Golestani
10
Rez Golestani  

Hi to All

I'm newbie in mql5 and python.

The question is that how can i SOTRE  time series information from metatrader5 to python as csv file? 

Thanks in advance