i.e: mt5.Close(symbol='GBPJPY', ticket = 233458963)
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
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.
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.
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.
Your Python script runs independently ....
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, sys.argv
(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.
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?
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
be sure to check everything before using Python with MT5 -
Forum on trading, automated trading systems and testing trading strategies
order_send failed, retcode=10027
Vladimir Karputov, 2021.08.25 20:18
I think I found your error:
Please enable the necessary setting in your browser, otherwise you will not be able to log in.