
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
My point is that the integration of python with MT5 is not complete. You cannot get indicator values DIRECTLY
Reading data to python
The aims of the topic are as simple as five pennies: to allow everyone to start algorithmic trading in Python, just by copying bits of code like initializing communication with the terminal, requesting quotes, asking the server to open or close a trade, etc., etc. Concentrate on logic only, and in an extremely easy to use language.
Right... logic is exactly what's missing for algorithmic trading - the logic that you need to test a trading strategy before "all comers" insert pieces of code and get into real trading
good luck with your "non-mythical" goals anyway
)))
People who don't need prices saved to files will rewrite the code a bit, and do not "write to files - read from files", but just the data structure they want. It's largely just a showcase of primitive things, for those willing to take the first steps.
However, those already familiar with concepts such as lists, tuples, dictionaries, etc.
I propose to read from price files with the function read_all_files_with_prices, which will trigger the function read_file_with_prices to read the price file of each instrument.Let read_file_with_prices function return either array numpy.ndarray with rows and columns corresponding to the original price file (if prices were successfully read and checked for data integrity, each element type is numpy.float64), or 'no data' string if data was not read or is incomplete .
Let the read_all_files_with_prices function return a dictionary with quotes for all instruments. Suppose that the keys in this dictionary are the instruments names, and the values are the dictionaries with quotes of one corresponding instrument. In the dictionaries with quotes for one symbol the keys are date_time, the values are bars (class bar); besides, I suggest to provide keys :
'is_data': key value - True if there is a quote, False - if reading from file returned 'no data',
'instrument': key value - instrument (str);
'prices': key-value - array of prices by instrument (numpy.ndarray)
In short, this is the data structure I suggest:
Python code is better placed as screenshots from the IDE/editor/site.
The local lack of highlighting, at least of code comments, makes it poorly readable, it blends in with the main text.
Added functions to read files and create the above data structure:
Python code is better placed as screenshots from the IDE/editor/site.
The local lack of highlighting, at least for code comments, makes it poorly readable, it blends in with the main text.
But it can be copied and opened in IDE, but from the image it can be retyped manually except...
The work of the program shown above:
Basically, almost everything is ready to start analysing data and making and executing trading decisions.
But it can be copied and opened in the IDE, while the image can only be retyped by hand...
I don't think anyone's going to bother copying and pasting the code... no one needs it here
to read and discuss, yes. Pick up something curious or give some hints. And I don't think I'll lug it around in IDE. People publish on forum for reading by others and for using the code either attach it or link to repository (or combine them).
But this is distracting.
Put the following code into the Functions.py file, a function that calculates SMA
I need parameters d and k to perform a time shift, not the point, we will set them to zeros.
I'll come up with some simple dumb logic, like:
for each instrument we calculate SMA lagging by z=100 intervals between samples, i.e. SMA of the order s=1+2*z=201.
If there are no trades in the market or their quantity (for a certain symbol) is lower than the admissible quantity (separately for Sell and Buy)
if the price is currently 30 pips or more above SMA(201) - open Sell deal with SL=TP=50 pips,
if the price is currently 30 pips or more below the SMA(201) - open a Buy trade with SL=TP=50 pips.
If at any time profit on the trade reaches 20 pips - close it without waiting for closing by SL or TP.
Let's implement such a trade as an example. Simple, silly, from the trading point of view, but the essence of the matter is implementation.
I suggest such functions for opening and closing trades: