MetaTrader 5 Python User Group - how to use Python in Metatrader - page 74

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Good afternoon everyone!
I don't know if I'm writing in the right thread, but I hope you can correct me. And one more thing to clarify - I'm a total zero in programming!
So, I've found a code of a small program written in PYTHON that takes a quote of EUR/USD pair from well-known site and writes it in A1 cell of EUR_USD_QUOTE.csv file.
If someone has not mind, please improve this code so that a quote is automatically updated in the same cell A1 of EUR_USD_QUOTE.csv file every hour.
Sincerely, Vladimir.
Good afternoon everyone!
I don't know if I'm writing in the right thread, but I hope you can correct me. And one more thing to clarify - I'm a total zero in programming!
So, I've found a code of a small program written in PYTHON that takes a quote of EUR/USD pair from well-known site and writes it in A1 cell of EUR_USD_QUOTE.csv file.
If someone has not mind, please improve this code so that a quote is automatically updated in the same cell A1 of EUR_USD_QUOTE.csv file every hour.
Sincerely, Vladimir.
I've launched the finalized code in PyCharm development environment, but nothing happens yet, only the "Rerun" button is activated. I can't understand yet - does the code work or not?
There is some additional information displayed in the "Problems" tab:
Maxim, can you temporarily make the quote in the file update now at least in 1 minute to understand whether the code is working or not, otherwise I have to wait a whole hour...?
One more thing. After I had launched the initial code that I had published earlier, file EUR_USD_QUOTE.csv was immediately opened with current quote, while the modified code cannot open this file.
Maybe I'm doing something wrong or I don't understand something? Please, advise me.
Regards, Vladimir.
Thank you, Maxim!
I've run the finalized code in PyCharm development environment, but nothing happens yet, only the "Rerun" button is activated. I can't understand yet - does the code work or not?
There is also additional information displayed in the "Problems" tab:
Maxim, can you temporarily make the quote in the file update now at least in 1 minute to understand whether the code is working or not, otherwise I have to wait a whole hour...?
One more thing. After I had launched the initial code that I had published earlier, file EUR_USD_QUOTE.csv was immediately opened with current quote, while the modified code cannot open this file.
Maybe I'm doing something wrong or I don't understand something? Please, advise me.
Regards, Vladimir.
1st 2 errors - just move this to the very top of the file
This is just a programming style warning, not an error
For a quick check, replace both fields
to
second
the file should be written every 10 seconds because the check timer is set to 10 seconds.
P.S. Just don't get too carried away or you'll get banned for too frequent requests.
on parentheses I do not have any errors
This code waits until the next hour and then only saves
I do not have these modules installed
so haven't checked
Maxim, I changed your code a little by "scientific experiment" method (please excuse me beforehand) and it worked out to open EUR_USD_QUOTE.csv file with current quote in 1 minute after launching.
But if I don't close EUR_USD_QUOTE.csv file during next minute, I get this message:
Traceback (most recent call last):
File "C:/Users/Vladimir/PycharmProjects/My_Python_Project/8.py", line 36, in <module>
get_data(save_file='EUR_USD_QUOTE.csv')
File "C:/Users/Vladimir/PycharmProjects/My_Python_Project/8.py", line 21, in get_data
with open(save_file, 'w') as save:
PermissionError: [Errno 13] Permission denied: 'EUR_USD_QUOTE.csv'
Process finished with exit code 1
How can I make the process continue without human intervention after the program code has been executed?
Regards, Vladimir.
Maxim, I changed your code a little by "scientific experiment" method (please excuse me beforehand) and it was possible to open EUR_USD_QUOTE.csv file with current quote in 1 minute after launching.
But if I don't close EUR_USD_QUOTE.csv file during next minute, I get this message:
Traceback (most recent call last):
File "C:/Users/Vladimir/PycharmProjects/My_Python_Project/8.py", line 36, in <module>
get_data(save_file='EUR_USD_QUOTE.csv')
File "C:/Users/Vladimir/PycharmProjects/My_Python_Project/8.py", line 21, in get_data
with open(save_file, 'w') as save:
PermissionError: [Errno 13] Permission denied: 'EUR_USD_QUOTE.csv'
Process finished with exit code 1
How can I make the process continue without human intervention after the program code has been executed?
Regards, Vladimir.
ah yes, because the process is busy os.startfile() for some reason, delete this line
и
can be removed
Checked it, it works.
and yes, because the process is busy os.startfile() for some reason, delete that line
и
can be deleted.
Checked it, it works.
Maxim, did everything as you advised. No more problems reported. The program has started but now how can I view the quote if EUR_USD_QUOTE.csv file is closed and when I open it and leave it open I get the same message that PermissionError: [Errno 13] Permission denied: 'EUR_USD_QUOTE.csv' and the quote in the open file is no longer updated?
Once again, please excuse me, I've never concealed that I am a total zero in programming.
Regards, Vladimir.
Maxim, I have done everything as you advised. There are no more messages about problems. Now how can I view the quote if EUR_USD_QUOTE.csv file is closed and when I open it and leave it open, I get the same message that PermissionError: [Errno 13] Permission denied: 'EUR_USD_QUOTE.csv' and the quote in the open file is no longer updated?
Please excuse me once again, I've never concealed that I am a total zero in programming.
Regards, Vladimir.
Do you open the file with Excel? It means it opens the file monopolistically. You have to allow other applications/users to modify the file.
Maybe http://blog.depit.ru/odnovremennaya-rabota-v-e xcel/ will help.
In general, you can't modify a file opened in another program.
You open the file with Excel? So it opens the file monopolistically. You have to allow other applications/users to modify the file somewhere in the settings.
Maybe http://blog.depit.ru/odnovremennaya-rabota-v-e xcel/ will help.
You can't modify a file opened in another program.
Yes, I'm opening it in Excel. I still cannot update the quote in the open EUR_USD_QUOTE.csv file in real time.
It was the idea to look at the table and see the changes in the quote.
Regards, Vladimir.