I will start with a piece of code, which may come in handy (I plan to work with M5 timeframe, perform calculations and make a decision once every 5 minutes):
import datetime as dt
class date_time(dt.datetime): ''' Класс описывает отсчёт даты и времени. Представляет собой расширение класса datetime библиотеки datetime. ''' @property def M5_view(self): minute = (self.minute//5)*5 if minute < 10: _minute = '0'+str(minute) else: _minute = str(minute) return self.strftime('%Y%m%d%H')+_minute @property def nice_view(self): return self.strftime('%Y.%m.%d %H:%M:%S') def __str__(self): return self.M5_view def __repr__(self): return self.__str__()
Thanks to this class, it will be convenient to log what is happening.
For example, write something like this
dt_stamp_read = ... print('\n'+date_time.now().nice_view, '- начал работу, планирую прочитать файлы с ценами в {}'.format(dt_stamp_read.nice_view))
and get output like:
2021.12.11 22:41:23 - начал работу, планирую прочитать файлы с ценами в 2021.12.11 22:45:30
You'll need it too:
class Bar: ''' Класс описывает бар, то есть структуру данных, удобную для описания изменения цен финансовых инструментов на интервалах времени. ''' def __init__(self, instrument, time_frame, time_close, price_open, price_low, price_high, price_close, pips_value): self.instrument = instrument self.time_frame = time_frame self.time_close = time_close self.time_open = self.time_close - dt.timedelta(minutes=self.time_frame) self.price_open = price_open self.price_low = price_low self.price_high = price_high self.price_close = price_close self.w = pips_value def __str__(self): str1 = '(Bar: instrument={} time_frame={} time_open={} time_close={}\n' str2 = 'open={} low={} high={} close={} pips_value={})' return (str1+str2).format(self.instrument, self.time_frame, self.time_open.M5_view, self.time_close.M5_view, self.price_open, self.price_low, self.price_high, self.price_close, self.w) def __repr__(self): return self.__str__()
The font here is not monospaced, so visually the formatting has gone a bit off, but that's not the point
Please insert the code correctly: first press , then insert the code in the pop-up window.
I'm asking someone to suggest a simple (knowingly losing, not the point) trading strategy.
If the message is sane, that is, will be more or less clearly set out what needs to be done, implement here, in this thread, trade on this strategy, in Python.
I am waiting )
Rewrite the standard MACD Expert Advisor that comes with MT5. It will be handy to check at all stages.
I will ask more specifically about the intended way of testing-optimization. Is it a self-written tester or a third-party tester based on Python? Integration with MQL5 through files, sockets, etc.?
Trading with python is good...
But python is good for analysing data, but not for trading.
If you consider the MACD option, on python:
- it is easy to load quotes;
- MACD data can be easily calculated;
Then on each new bar take a condition, for example: MACD value and signal line, steepness of the slow and fast line, price movement away from the slow line...
Run the condition through history and show statistics plus/minus of the specified formation for a certain period. Everything else (opening/closing/taking trades) should be done in MQL.
You don't have to invent a tester - we have a ready-made one.
In Python the quotes and indicators are stored on SQLite. Connection MQL - python through socket, files or database (socket is better).
Everything...
Python - only for data analysis with the rich ability to display analysis results as 2d(3d) graphs.
copy_rates_from is not sufficient for complete data analysis. If it were possible to extract indicator data (including custom indicators), the analysis ring would be closed.
And trading via python, IMHO is a PR move by MQL5.
I will implement this strategy here in this thread in Python.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm asking someone to suggest a simple (knowingly losing, not the point) trading strategy.
If the message is sane, that is, will be more or less clearly set out what needs to be done, implement here, in this thread, trade on this strategy, in Python.
I'm waiting )