Structure rules. Learning how to structure programmes, exploring possibilities, errors, solutions, etc. - page 6

 
FAQ:

ZS. It's a bit small, so why don't we do a more global one?

Do you have a concrete proposal?
 
MetaDriver :

Well, tady prick (in general terms) how do you plug these gaps in the top four. Is everything in DLLs? :)

No DLL, pure MCL + winepi for event handling .

Regarding this, we need to find time to describe everything beautifully and make a great article. I can throw either an example or an implementation of visual pseudo-classes for MT4, but I'm afraid it will be hard to digest without a detailed description. The essence of creating a DOM (Data Object Module) for MT by analogy with JS - they are really similar anyway. For seed - the main function of the heart so to speak:

 //+------------------------------------------------------------------+
//| Brief Description included Functions                             |
/*+----exported function---------------------------------------------+
bool   ObjSet(ObjNm,ObjTyp,isets[],tsets[],{ObjParent})Устанавливает на график объект класса Interface.
void   ObjDelete(string nm,bool delChild=true) Удаляет объект с графика, вместе , или без первого потомка
void   ObjsDelete(string nm) Удаляет объект, вместе со всеми его потомками
double ObjGet(string nm, int prop_id) Ищет объект и возвращает значение его свойства
bool   ObjSearch(string ObjNm):int[];string; Возвращает признак наличия объекта класса Interface
int    This(int prop_id) Ищет значение свойства объекта в списке свойств : obj_props[10]
//+----internal function---------------------------------------------+
string ObjGetName(string,int[],{string})  Собирает полное имя объекта класса Interface
void   ObjSetLabel()Обертка для стандартной функции
*/ //+----------------------------------------------------------------+
//|                                      OBJECTS_INTERFACE_CLASS.mq4 |
//|           Copyright © 2012, XrustSolution. mail:xrustx@gmail.com |
//|          https://www.youtube.com/user/opmlv http://forexrust.info |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, XrustSolution."
#property link        "mail: xrustx@gmail.com https://www.youtube.com/user/opmlv http://forexrust.info"
//+------------------------------------------------------------------+
//|   Extern variables                                               |
//+------------------------------------------------------------------+
extern    string    ObjectsInterfaceSettings = "-------- ObjectsInterfaceSettings ----------" ;
extern    int       X_Distance                                = 2       ;
extern    int       Y_Distance                                = 2       ;
extern    int       ChartCorner                               = 0       ;

//+------------------------------------------------------------------+
//|   Defines                                                        |
//+------------------------------------------------------------------+
#define GlobalPrefix     "wnd:"    // Префикс имени класса
#define GlobalParent     "chart"    // Имя глобального родителя
#define hName           "Header" // Имя главного родителя (заголовка)
#define wName           "Window" // Имя главного окна
#define cName           ""        // Стандартное имя текущего объекта
#define tName           "Txt"    // Стандартное имя для текстовой строки
#define Objects 500                // Максимальное количество командных объектов
//+------------------------------------------------------------------+
//|   Global variables                                               |
//+------------------------------------------------------------------+
string ObjParent = "" ;           // Глобальное имя родителя Object Parent Name
string ObjName   = "" ;           // Глобальное имя объекта  Object Own Name
int     obj_props[ 10 ];             // Набор свойств объекта : {xdLeft,ydUp,xdRight,ydDown,zIndex,Class,Corner,Color,Window};
//+------------------------------------------------------------------+
string   ObjsParent[Objects];     // Список имен родителей командных объектов
string   ObjsNames[Objects];       // Список имен командных объектов
int      CommObjs[Objects][ 6 ];     // Список параматров командных объектов = {класс,угол,х0,у0,х1,у1}
string   ObjsDom[Objects][ 2 ];     // Список всех объектов и их дочерних элементов (объектов) ObjsDom[Parent][Childrens]
string   ObjsDel[ 5000 ];           // Список старых объектов для удаления при перемещении окон  
string   ObjsName[ 5000 ];       // Список полных имен объектов
//+------------------------------------------------------------------+
//|   Defines                                                        |
//+-----ObjectsTypes-------------------------------------------------+
#define         OBJ_CANVAS       30        // Холст\Окно\Прямоугольник (Основной элемент)
//+---Предопределенные типы окон-------------------------------------+
#define         OBJ_WINDOW     31 // Пустое окно
#define         OBJ_TXTWND     32 // Текстовое окно с форматированием текста
#define         OBJ_HTMWND     33 // Текстовое окно с форматированием, активными ссылками
#define         OBJ_CHARTW     34 // Псевдографическое окно с возможностями граф построений
//#define       OBJ_LEDWND     34 // 

//+---Кнопки командные-----------------------------------------------+ 
#define   OBJ_BUTTON      40 // Кнопка (пустая) общего назначения
//----Кнопки предопределенные(Команда)
#define   OBJ_BUTBUY     41 // OP_BUY
#define   OBJ_BUTSEL     42 // OP_SELL
#define   OBJ_BUTCLO     43 // ORDER_CLOSE
#define   OBJ_BUTREV     44 // ORDER_REVERSE
#define   OBJ_BUTBST     45 // OP_BUYSTOP
#define   OBJ_BUTBLM     46 // OP_BUYLIMIT
#define   OBJ_BUTSST     47 // OP_SELLSTOP
#define   OBJ_BUTSLM     48 // OP_SELLLIMIT
#define   OBJ_BUTDEL     49 // ORDER_DELETE
//+---Ярлыки командные (кнопки 1х1 с значком)------------------------+
#define   OBJ_LABCNT     50 // Командный ярлык (Контрол) Без обкладки в виде канваса 1х1 наследие двигательного аппарата команд
#define   OBJ_LABCOM     51 // Командный ярлык кнопка 1х1 с канвасом (пустой) 
//----Ярлыки предопределенные(Команда)
         /*----Группа ярлыков кнопок находящихся в заголовке (верхнем меню)---*/
#define   OBJ_LABCLO     52 // Ярлык/Кн.закрыть
#define   OBJ_LABHID     53 // Ярлык/Кн.Свернуть
#define   OBJ_LABSHW     54 // Ярлык/Кн.развернуть
#define   OBJ_LABSET     55 // Ярлык/Кн.Настройки
         /*----Двухцветные ярлычки (триггеры(серый\зеленый))----*/
#define   OBJ_LABALR     56 // Ярлык/Кн.Алерт
#define   OBJ_LABSND     57 // Ярлык/Кн.Звук
#define   OBJ_LABEML     58 // Ярлык/Кн.Мыло
#define   OBJ_LABSEL     59 // Ярлык/Кн.Select\Unselect
         /*----Группа ярлыков стрелок и др предустановленных спец символов---*/
#define   OBJ_LABLFT     60 // Ярлык/Стрелка Влево
#define   OBJ_LABRGT     61 // Ярлык/Стрелка Вправо
#define   OBJ_LABUP       62 // Ярлык/Стрелка Вверх
#define   OBJ_LABDWN     63 // Ярлык/Стрелка Вниз
     
#define   OBJ_LAB_TXT     69 // Текстовая строка / значек в ярлыке
//+----Хидеры(заголовки)-Основной родительский объект, наследует все остальные+
#define   OBJ_HD         70 // Пустой хидер (прямоугольник 1 размера блока)
#define   OBJ_HDC         71 // + Кнока закрытия
#define   OBJ_HDH         72 // + Кнопка свернуть\развернуть
#define   OBJ_HDCH       73 // + закрыть + развернуть
#define   OBJ_HDCHT       74 // + закрыть + развернуть + настройки
#define   OBJ_HDСHTS     75 // + закрыть + развернуть + настройки + системное меню алертов
//+-----ObjectProperties---------------------------------------------+
#define   OBJ_PRP_X0         17    // левая координата (Х0)
#define   OBJ_PRP_Y0         18    // верхняя координата (Y0)
#define   OBJ_PRP_X1         19    // правая координата (Х0) 
#define   OBJ_PRP_Y1         20    // нижняя координата (Х0)
#define   OBJ_PRP_ZI         21    // Зет Индекс
#define   OBJ_PRP_CLS         22    // Класс Объекта
#define   OBJ_PRP_CRN         23    // Угол привязки объекта
#define   OBJ_PRP_CLR         24    // Цвет
#define   OBJ_PRP_WND         25    // Окно в котором объект находиться
#define   OBJ_PRP_LAY         26    // Резерв (здесь будет количество слоев, для более точного определения параметров элементов)
//+-----Массив аргументов для функции GetObjectName()----------------+
int      Props[ 10 ];                                                      
//              Props[0] = Лево         
//              Props[1] = Верх 
//              Props[2] = Право        
//              Props[3] = Низ  
//              Props[4] = Счетчик по Х 
//              Props[5] = Счетчик по У 
//              Props[6] = Зет индекс (основной)        
//              Props[7] = Зет индекс (дополнительный для объектов из нескольких слоев) 
//              Props[8] = Идентификатор зет индекса последнего (верхнего) слоя в объекте
//              Props[9] = Идентификатор типа объекта                                           
//+---Массивы с корректыми размерами шрифтв Webdings для >= 416 билда---------------+
int realSz[ 21 ] = { 15 , 23 , 31 , 35 , 43 , 47 , 55 , 67 , 75 , 83 , 87 , 91 , 95 , 99 , 119 , 123 , 127 , 143 , 148 , 156 , 164 }; // Таблица реальных размеров
int fontSz[ 21 ]  = { 11 , 17 , 23 , 26 , 32 , 35 , 41 , 50 , 56 , 62 , 65 , 68 , 71 , 74 , 89 , 92 , 95 , 107 , 110 , 116 , 122 }; // Таблица корректных шрифтов
int szCorr[ 21 ] = { 4 , 5 , 6 , 7 , 9 , 10 , 12 , 15 , 17 , 19 , 20 , 21 , 22 , 23 , 28 , 29 , 30 , 34 , 36 , 38 , 40 }; // Разница между размером шрифта, и реальным размером
int vertCr[ 21 ] = {- 3 ,- 2 ,- 1 ,- 1 ,- 2 , 0 ,- 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,   0 , - 1 ,   0 ,   0 ,   0 ,   0 ,   0 }; // Таблица cмещения по вертикали от размера шрифта

//+------------------------------------------------------------------+
//|  Includes                                                        |
//+------------------------------------------------------------------+
#include <OBJ_CANVAS.mqh> //SetCanvas(onm,xd,yd,xs,ys,[sz,zindx,oClr,crn,wnd,pnm,bord,bClr]);
#include <OBJ_LAB_TEXT.mqh> //SetTextString(onm,pnm,typ,txt,fnm,clr,[center,xd,yd,psz,fsz,crn,wnd]):int:error;
//#include <OBJ_BUTTON.mqh>//SetButton(onm,pnm,type[,xd,yd,xs,ys,text,tx_fnt,txClr,sz,bgClr,bdClr,crn,wnd]);
#include <OBJ_HEADER.mqh>
#include <OBJ_LED_SIMPLE.mqh>
//+------------------------------------------------------------------+
//|           Function  : string GetObjectName(string,int[],{string})|
//|           Copyright © 2012, XrustSolution. mail:xrustx@gmail.com |
//|          https://www.youtube.com/user/opmlv http://forexrust.info |
//+------------------------------------------------------------------+
//|                     Собирает полное имя объекта класса Interface |
//+------------------------------------------------------------------+
//|Полное имя объекта должно состоять из :                           |
//|wnd:        = Основной префикс имени                         4 зн |
//|z_0ax:      = Z индекс для опр. порядка отображения окна 1-9 6 зн |10 зн
//|c_30:       = Тип объекта класса (смотреть в списке типов)   5 зн |15 зн
//|lu_xxx_yyy: = Координаты левого верхнего угла               10 зн |25 зн
//|rd_xxx_yyy: = Координаты правого нижнего угла               10 зн |35 зн
//|id_xxx_yyy: = Номера объектов                               10 зн |45 зн
//|#name|parent= Собственное имя обьекта из максимум 15 знаков,    до|60 зн
//|состоящее из имени элемента класса, и имени родительского объекта |
//+------------------------------------------------------------------+
//|Разделители:  типов свойств     = двоеточите(:),                  |
//|              значений свойств  = нижнее подчеркивание(_)         |
//|              имя объекта       = решетка(#)конец описания свойств|
//|              имя родителя      = слеш[|]                         |
//+------------------------------------------------------------------+
string     ObjGetName( string Name,                                   // Имя объекта
                                                         int       Props[],                                 // Набор свойств объекта
                                                         string Parent = GlobalParent                   // Имя родителя, по умолчанию = "chart" , то есть основное окно графика
                                                        ){ string out= "" ;
//+------------------------------------------------------------------+
   if (Parent== "" ){Parent = "chart" ;}
   if (Props[ 9 ]!=OBJ_LAB_TXT){ // если объект текстовая строка добавляем в описание имя шрифта
        out = StringConcatenate (GlobalPrefix,                                   //
                                                                         "z_" ,Props[ 6 ],StringSetChar( "" , 0 ,Props[ 7 ]+ 97 ),StringSetChar( "" , 0 ,Props[ 8 ]+ 97 ), ":" ,
                                                                         "c_" ,Props[ 9 ], ":" ,
                                                                         "lu_" ,Props[ 0 ], "_" ,Props[ 1 ], ":" ,
                                                                         "rd_" ,Props[ 2 ], "_" ,Props[ 3 ], ":" ,
                                                                         "id" ,Props[ 4 ], "" ,Props[ 5 ], ":" ,
                                                                         "#"   ,Name    , "|" ,Parent);
        } else { // работаем как обычно
        out = StringConcatenate (GlobalPrefix,                                   //
                                                                         "z_" ,Props[ 6 ],StringSetChar( "" , 0 ,Props[ 7 ]+ 97 ),StringSetChar( "" , 0 ,Props[ 8 ]+ 97 ), ":" ,
                                                                         "c_" ,Props[ 9 ], ":" ,
                                                                         "lu_" ,Props[ 0 ], "_" ,Props[ 1 ], ":" ,
                                                                         "fn_font_name:" ,
                                                                         "id" ,Props[ 4 ], "" ,Props[ 5 ], ":" ,
                                                                         "#"   ,Name    , "|" ,Parent);
        }                                                               
         return (out);
}
MetaDriver :
Have a specific offer?

There is, and the task is alive, but I'm afraid to pronounce it here, I can in a personal.

 
C-4:
Nowadays, no normal programmer draws flowcharts. This is all theoretical nonsense designed to be taught to schoolchildren, but not to work in real projects.
It is not nonsense. It was necessary when programs were written in machine codes. And then they were dragged into textbooks and became nonsense when programs were described in normal languages. And then there was the USPD, the Unified System for Program Documentation. And in order to submit it to the customer it had to be drawn up according to very strict rules. There had to be a block diagram and all sorts of descriptions.
 
FAQ:

No DLL, pure MCL + Vinapi for event processing.

Regarding this, I need to find time to describe everything nicely and make a big article. I can throw either example or implementation of visual pseudoclasses for MT4, but I'm afraid it will be hard to digest without detailed description. The essence is to create DOM (Data Object Module) for MT by analogy with JS - they are really similar. For a primer - the main function of the heart so to speak:

(Yes, with a swing. ))

DOM - that's a lot. Give me a couple of screenshots at least... Or (if available) some standalone compiled example, to feel it in the terminal. Got one?

 
MetaDriver:

(Laughs...) With a bang. ))

DOM - that's a lot. Give me a couple of screenshots at least... Or (if available) some standalone compiled example, to feel it in the terminal. Got one?

check it out here :https://www.youtube.com/user/opmlv there's a wagonload of stuff to trace how it evolved :)
Rustamzhan Salidzhanov
Rustamzhan Salidzhanov
  • www.youtube.com
Краткая сборка софта созданного мной , для торговой платформы MetaTrader 4. Все имущественные права на данный софт принадлежат заказчикам, как правообладателям. И не могут быть переданы третим лицам без их (правообладателей) согласия. Я за собою оставляю авторское право как создатель данного софта. Quick assembly of software created by me for...
 
MetaDriver:

Shall we take a crack at it?

Nothing.

1. The panel is right at the tail end. the strategy is primary, if it doesn't work, the panel is pointless and useless.

2. The implementation of the trading part depends on the strategy, so there is nothing to discuss in the framework of storming a hypothetical strategy. The implementation of the strategy, oddly enough, also depends on the strategy :)

3. Immediately make a trigger to disable the strategy accounted for in the trading block. And disable the placing of new orders.

4. Panel. What a panel is - a routine.

 

As for the writing of the TS, it goes something like this:

Forum on trading, automated trading systems and trading strategy testing

Discussion of High Frequency Trading on MT5

hrenfx, 2013.02.06 14:30


Простой и довольно эффективной логикой написания боевого робота является следующая схема:
- робот делится на две части: тестер и синхронизатор.
- тестер на основании ранней истории и только что пришедшей выдает текущее состоянии торговой стратегии.
- синхронизатор "переносит" текущие тестерные открытые позиции и приказы на реал.

Это чем-то напиминает копирование торговых сигналов с одного счета на другой. Только вместо примитивного копировщика работает грамотный синхронизатор.

К сожалению, правильную логику синхронизатора посмотреть где-либо практически невозможно, поэтому озадачевшемуся придется подумать самому - очень полезно.

Но и такая логика построения боевого-робота далеко не совершенна, т.к. встает дилема первичности курицы и яйца. Поэтому применяются более сложные свои схемы, основанные на опыте автора-алготрейдера.

Все эти действия совершаются только ради одного - адекватной настройки стратегии. Какой бы совершенной не была схема, все равно одинаковые боевые роботы на разных счетах одного и того же ECN/STP брокера покажут расхождения. И помимо поиска рыночных закономерностей, важной задачей для алготрейдера также является уменьшение этих расхождений. Как уже говорилось выше, чем ближе брокер к возможстям HFT, тем меньше расхождения.

Если вникнуть в написанное, должно прийти понимание, что результаты работы стратегии на реале являются также своего рода тестером. И выводы на основании этой торговли также должны быть вероятностными.

 
TheXpert:

Nothing.

1. The panel is straight to the tail. the strategy is primary, if it doesn't plough on, the panel is pointless and useless.

2. The implementation of the trading part depends on the strategy, so there is nothing to discuss in the framework of a hypothetical strategy assault. The implementation of strategy oddly enough depends on strategy too :)

3. Immediately make a trigger to disable the strategy accounted for in the trading block. And disable the placing of new orders.

4. Panel. What a panel - a routine.

Well, here we have something to argue about at once. :))

Not to argue, let's say, but to point out the possibilities:

1. Panel straight to the tail. strategy is primary, if it won't plough on, the panel is pointless and useless.

For now, I agree, but with a caveat: the program should be immediately oriented to work in two modes, so the strategy / trading part should be prescribed at once, taking into account the presence / absence of control from the panel and with / without display of information on the panel.

2. Implementation of the trading part depends on the strategy, .......

It doesn't depend on my strategy. The whole trading part is written in a class (CMarketDriver), which completely implements order placement, position tracking, requotes and other stuff related to trading. For all the symbols at once. The strategy part just receives recommended market positions for symbols: i.e. it fills in the array of structures of the format {string Instrument; double Position} and requests synchronization with the server: MD.Synchronize(PositionArray). That's all. For now it only trades with market orders but a version that trades with limits set inside spread (to reduce trade costs) is on the way. For trading takeprofits/stops do not use, but MarketDriver can put protective stops in case of long loss of connection to server (stop parameters are specified once in driver settings). By the way, very successful, almost no problems structured solution. For testing of strategic ideas in the tester - no problems with trading, all attention can be devoted to strategy - all trading has long been debugged and encapsulated in the trading driver.

2............., so there's nothing to discuss within the framework of a hypothetical strategy assault. The implementation of the strategy oddly enough depends on the strategy too :)

For example, I have a fresh idea - trade on intersection of a pair of wipers. In this case, the problem is to restructure the program so that when developing it (e.g. adding a third wiper), I will not have to change most of the code. Then the program may be developed towards multicurrency (for simplicity of the project, let us suppose that trading by symbols is strictly independent and interrelationships are not considered). How to organize the strategic part, anticipating such development?

3. Immediately set the trigger to disable the strategy taken into account in the trading block. And disable new order placing.

But we don't have to. After all, we do not expect much trouble here.

4. Panel. Well, the panel is a chore.

But the organization of the strategy's event-driven connection with the panel is quite a creative task, especially if we try to develop a more or less universal template for such a panel that can be easily adapted to different Expert Advisors and easily developed as the project grows/develops.

 
MetaDriver:

You don't have to, it almost never depends on me.

With me it almost always depends. Especially when working with ECN. I mean, everything is not done at the lowest level of course, but just through the shells of the standard trading functions.

Документация по MQL5: Торговые функции
Документация по MQL5: Торговые функции
  • www.mql5.com
Торговые функции - Документация по MQL5
 
TheXpert:

With me it almost always depends. Especially when working with ECN. I mean, everything is not done at the lowest level of course, but just through the shells of the standard trading functions.

Well, that's a bad kind of thing. I don't know how my relationship with ECN will turn out there (I'm going to open an account with RoboForex), but I will try my best to keep this structural decoupling (strategy/market driver). It is so convenient, that I am even ready for some moderate trading costs (like lost profit).

See how simple the main cycle of the EA looks in the end:

// Тестовый советник для тестирования обученных в GPU-оптимизаторе нейросеток (или записи значений котировок/индикаторов для отправки исходных данных в тот же оптимизатор).
void OnTick()
  {
   if(Mode==TradesMode) //-- Если режим тестирования
     {
      for(int i=0;i<CountInd;i++)
        {
         vInds[i]=GetInd(i,0);   // получаем значения индикаторов
        }
      Net.CalcResult(vInds);             // рассчитываем значение нейросетки
      float net_result=Net.NetResult[0];  // забираем рекомендованную рыночную позицию      
      SP.Pos=net_result*Lot;             // заполняем структуру для MarketDriver'a
      int err;
      MD.Synhronize(SP,err);             // синхронизируемся с торговым сервером.
     }
   else // Mode==RecordMode  // Если режим записи
..............
Check out the simplified tester version and see if you like the scheme. If so, fine-tune it to your needs and use it to your advantage.
Files: