├── .gitattributes ├── Images ├── euro.bmp ├── logo.bmp └── dollar.bmp ├── Templates ├── tester.tpl ├── default.tpl ├── template_dark.tpl └── template_light.tpl ├── Include ├── Controls │ ├── Button.mqh │ ├── res │ │ ├── Up.bmp │ │ ├── Close.bmp │ │ ├── Down.bmp │ │ ├── Left.bmp │ │ ├── Right.bmp │ │ ├── Turn.bmp │ │ ├── DropOff.bmp │ │ ├── DropOn.bmp │ │ ├── Restore.bmp │ │ ├── SpinDec.bmp │ │ ├── SpinInc.bmp │ │ ├── CheckBoxOn.bmp │ │ ├── DateDropOn.bmp │ │ ├── DownTransp.bmp │ │ ├── LeftTransp.bmp │ │ ├── ThumbHor.bmp │ │ ├── ThumbVert.bmp │ │ ├── UpTransp.bmp │ │ ├── CheckBoxOff.bmp │ │ ├── DateDropOff.bmp │ │ ├── RightTransp.bmp │ │ ├── RadioButtonOff.bmp │ │ └── RadioButtonOn.bmp │ ├── BmpButton.mqh │ ├── ListView.mqh │ ├── Scrolls.mqh │ ├── RadioGroup.mqh │ ├── Label.mqh │ ├── Picture.mqh │ ├── Panel.mqh │ ├── RadioButton.mqh │ ├── CheckBox.mqh │ ├── Edit.mqh │ ├── SpinEdit.mqh │ ├── WndObj.mqh │ ├── DatePicker.mqh │ ├── Rect.mqh │ └── Defines.mqh ├── BadRobot.Framework │ ├── BadRobotCore.mqh │ ├── BadRobotPrompt.mqh │ ├── Enum.mqh │ ├── Account.mqh │ └── Logger.mqh ├── StdLibErr.mqh ├── Object.mqh ├── Files │ ├── FileTxt.mqh │ └── File.mqh ├── Arrays │ ├── TreeNode.mqh │ └── Array.mqh ├── ChartObjects │ ├── ChartObjectsShapes.mqh │ ├── ChartObjectPanel.mqh │ ├── ChartObjectsElliott.mqh │ └── ChartObjectsChannels.mqh ├── Trade │ └── TerminalInfo.mqh └── Canvas │ └── Charts │ └── HistogramChart.mqh ├── how_to_install_badrobot.gif ├── install_from_git_bash.md ├── .gitignore ├── .gitmodules ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mq5 diff=tex 2 | *.mqh diff=tex -------------------------------------------------------------------------------- /Images/euro.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Images/euro.bmp -------------------------------------------------------------------------------- /Images/logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Images/logo.bmp -------------------------------------------------------------------------------- /Images/dollar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Images/dollar.bmp -------------------------------------------------------------------------------- /Templates/tester.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Templates/tester.tpl -------------------------------------------------------------------------------- /Templates/default.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Templates/default.tpl -------------------------------------------------------------------------------- /Include/Controls/Button.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/Button.mqh -------------------------------------------------------------------------------- /Include/Controls/res/Up.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Up.bmp -------------------------------------------------------------------------------- /Templates/template_dark.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Templates/template_dark.tpl -------------------------------------------------------------------------------- /how_to_install_badrobot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/how_to_install_badrobot.gif -------------------------------------------------------------------------------- /Include/Controls/BmpButton.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/BmpButton.mqh -------------------------------------------------------------------------------- /Include/Controls/ListView.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/ListView.mqh -------------------------------------------------------------------------------- /Include/Controls/Scrolls.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/Scrolls.mqh -------------------------------------------------------------------------------- /Include/Controls/res/Close.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Close.bmp -------------------------------------------------------------------------------- /Include/Controls/res/Down.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Down.bmp -------------------------------------------------------------------------------- /Include/Controls/res/Left.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Left.bmp -------------------------------------------------------------------------------- /Include/Controls/res/Right.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Right.bmp -------------------------------------------------------------------------------- /Include/Controls/res/Turn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Turn.bmp -------------------------------------------------------------------------------- /Templates/template_light.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Templates/template_light.tpl -------------------------------------------------------------------------------- /Include/Controls/RadioGroup.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/RadioGroup.mqh -------------------------------------------------------------------------------- /Include/Controls/res/DropOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/DropOff.bmp -------------------------------------------------------------------------------- /Include/Controls/res/DropOn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/DropOn.bmp -------------------------------------------------------------------------------- /Include/Controls/res/Restore.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/Restore.bmp -------------------------------------------------------------------------------- /Include/Controls/res/SpinDec.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/SpinDec.bmp -------------------------------------------------------------------------------- /Include/Controls/res/SpinInc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/SpinInc.bmp -------------------------------------------------------------------------------- /Include/Controls/res/CheckBoxOn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/CheckBoxOn.bmp -------------------------------------------------------------------------------- /Include/Controls/res/DateDropOn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/DateDropOn.bmp -------------------------------------------------------------------------------- /Include/Controls/res/DownTransp.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/DownTransp.bmp -------------------------------------------------------------------------------- /Include/Controls/res/LeftTransp.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/LeftTransp.bmp -------------------------------------------------------------------------------- /Include/Controls/res/ThumbHor.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/ThumbHor.bmp -------------------------------------------------------------------------------- /Include/Controls/res/ThumbVert.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/ThumbVert.bmp -------------------------------------------------------------------------------- /Include/Controls/res/UpTransp.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/UpTransp.bmp -------------------------------------------------------------------------------- /Include/Controls/res/CheckBoxOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/CheckBoxOff.bmp -------------------------------------------------------------------------------- /Include/Controls/res/DateDropOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/DateDropOff.bmp -------------------------------------------------------------------------------- /Include/Controls/res/RightTransp.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/RightTransp.bmp -------------------------------------------------------------------------------- /Include/Controls/res/RadioButtonOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/RadioButtonOff.bmp -------------------------------------------------------------------------------- /Include/Controls/res/RadioButtonOn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/Controls/res/RadioButtonOn.bmp -------------------------------------------------------------------------------- /Include/BadRobot.Framework/BadRobotCore.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/BadRobot.Framework/BadRobotCore.mqh -------------------------------------------------------------------------------- /Include/BadRobot.Framework/BadRobotPrompt.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erlonfs/bad-robot.framework/HEAD/Include/BadRobot.Framework/BadRobotPrompt.mqh -------------------------------------------------------------------------------- /install_from_git_bash.md: -------------------------------------------------------------------------------- 1 | # Como instalar via git bash 2 | 3 | Baixe e instale o [Git](https://git-scm.com/downloads) para utilizar o `git bash` 4 | 5 | ![how_to_install](how_to_install_badrobot.gif) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Executaveis 2 | *.ex5 3 | #Outros 4 | experts.dat 5 | /Profiles 6 | /Indicators 7 | /Logs 8 | /Files 9 | 10 | /Include/Experts/ 11 | /Include/Generic/ 12 | /Include/Expert/ 13 | /Include/Graphics/ 14 | /Include/Indicators/ 15 | /Include/Math/ 16 | /Include/MovingAverages.mqh 17 | /Include/OpenCL/ 18 | /Include/Strings/ 19 | /Include/VirtualKeys.mqh 20 | /Include/WinAPI/ 21 | /Scripts/ 22 | 23 | 24 | /Include/Generic -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Experts/elephant-walk.bad-robot"] 2 | path = Experts/elephant-walk.bad-robot 3 | url = https://github.com/erlonfs/elephant-walk.bad-robot.git 4 | [submodule "Experts/first-candle.bad-robot"] 5 | path = Experts/first-candle.bad-robot 6 | url = https://github.com/erlonfs/first-candle.bad-robot.git 7 | [submodule "Experts/box.bad-robot"] 8 | path = Experts/box.bad-robot 9 | url = https://github.com/erlonfs/box.bad-robot.git 10 | [submodule "Experts/line.bad-robot"] 11 | path = Experts/line.bad-robot 12 | url = https://github.com/erlonfs/line.bad-robot.git 13 | [submodule "Experts/traderpad.bad-robot"] 14 | path = Experts/traderpad.bad-robot 15 | url = https://github.com/erlonfs/traderpad.bad-robot.git 16 | -------------------------------------------------------------------------------- /Include/StdLibErr.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| StdLibErr.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #define ERR_USER_INVALID_HANDLE 1 7 | #define ERR_USER_INVALID_BUFF_NUM 2 8 | #define ERR_USER_ITEM_NOT_FOUND 3 9 | #define ERR_USER_ARRAY_IS_EMPTY 1000 10 | //+------------------------------------------------------------------+ 11 | -------------------------------------------------------------------------------- /Include/BadRobot.Framework/Enum.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Copyright 2016, Erlon F. Souza | 3 | //| https://github.com/erlonfs | 4 | //+------------------------------------------------------------------+ 5 | 6 | #property copyright "Copyright 2016, Erlon F. Souza" 7 | #property link "https://github.com/erlonfs" 8 | 9 | #define ENUM_LOGIC_NAO (0) 10 | #define ENUM_LOGIC_SIM (1) 11 | 12 | #define ENUM_LAST_PRICE_TYPE_LAST (0) 13 | #define ENUM_LAST_PRICE_TYPE_ASK_OR_BID (1) 14 | 15 | enum ENUM_LOGIC 16 | { 17 | NAO = 0,//Não 18 | SIM = 1//Sim 19 | }; 20 | 21 | enum ENUM_LAST_PRICE_TYPE 22 | { 23 | LAST = 0,//Last Price 24 | ASK_OR_BID = 1//Ask ou Bid 25 | }; 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Erlon F Souza 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Include/BadRobot.Framework/Account.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Copyright 2018, Erlon F. Souza | 3 | //| https://github.com/erlonfs | 4 | //+------------------------------------------------------------------+ 5 | 6 | #property copyright "Copyright 2018, Erlon F. Souza" 7 | #property link "https://github.com/erlonfs" 8 | #property version "1.0" 9 | 10 | class Account 11 | { 12 | private: 13 | ENUM_ACCOUNT_TRADE_MODE _tradeMode; 14 | ENUM_ACCOUNT_MARGIN_MODE _marginMode; 15 | 16 | public: 17 | 18 | Account(){ 19 | _tradeMode = (ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE); 20 | _marginMode = (ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE); 21 | } 22 | 23 | ~Account(){ 24 | 25 | } 26 | 27 | 28 | bool IsReal(){ 29 | return _tradeMode == ACCOUNT_TRADE_MODE_REAL; 30 | } 31 | 32 | bool IsDemo(){ 33 | return _tradeMode == ACCOUNT_TRADE_MODE_DEMO; 34 | } 35 | 36 | bool IsHedging(){ 37 | return _marginMode == ACCOUNT_MARGIN_MODE_RETAIL_HEDGING; 38 | } 39 | 40 | 41 | 42 | }; -------------------------------------------------------------------------------- /Include/Object.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Object.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "StdLibErr.mqh" 7 | //+------------------------------------------------------------------+ 8 | //| Class CObject. | 9 | //| Purpose: Base class for storing elements. | 10 | //+------------------------------------------------------------------+ 11 | class CObject 12 | { 13 | private: 14 | CObject *m_prev; // previous item of list 15 | CObject *m_next; // next item of list 16 | 17 | public: 18 | CObject(void): m_prev(NULL),m_next(NULL) { } 19 | ~CObject(void) { } 20 | //--- methods to access protected data 21 | CObject *Prev(void) const { return(m_prev); } 22 | void Prev(CObject *node) { m_prev=node; } 23 | CObject *Next(void) const { return(m_next); } 24 | void Next(CObject *node) { m_next=node; } 25 | //--- methods for working with files 26 | virtual bool Save(const int file_handle) { return(true); } 27 | virtual bool Load(const int file_handle) { return(true); } 28 | //--- method of identifying the object 29 | virtual int Type(void) const { return(0); } 30 | //--- method of comparing the objects 31 | virtual int Compare(const CObject *node,const int mode=0) const { return(0); } 32 | }; 33 | //+------------------------------------------------------------------+ 34 | -------------------------------------------------------------------------------- /Include/BadRobot.Framework/Logger.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Copyright 2018, Erlon F. Souza | 3 | //| https://github.com/erlonfs | 4 | //+------------------------------------------------------------------+ 5 | 6 | #property copyright "Copyright 2018, Erlon F. Souza" 7 | #property link "https://github.com/erlonfs" 8 | #property version "1.0" 9 | 10 | #define MAX_SIZE_TEXT (50) 11 | 12 | class Logger 13 | { 14 | private: 15 | string _logs[10]; 16 | bool _hasChanges; 17 | 18 | void Add(string txt){ 19 | 20 | string newArray[]; 21 | ArrayCopy(newArray, _logs); 22 | 23 | for(int i = ArraySize(_logs) - 1; i > 0; i--){ 24 | _logs[i] = newArray[i - 1]; 25 | } 26 | 27 | _logs[0] = txt; 28 | _hasChanges = true; 29 | 30 | printf(txt); 31 | 32 | } 33 | 34 | public: 35 | 36 | Logger() 37 | { 38 | 39 | } 40 | 41 | ~Logger(void) 42 | { 43 | 44 | } 45 | 46 | Logger(const Logger& other){ 47 | this = other; 48 | } 49 | 50 | void Log(string text) 51 | { 52 | 53 | if(text == NULL) return; 54 | 55 | StringToUpper(text); 56 | StringTrimLeft(text); 57 | StringTrimRight(text); 58 | 59 | int length = StringLen(text); 60 | if(length > MAX_SIZE_TEXT + 3) 61 | { 62 | text = StringSubstr(text, 0, MAX_SIZE_TEXT - 3) + "..."; 63 | } 64 | 65 | string newText = (TimeToString(TimeCurrent(), TIME_SECONDS)) + " > " + text; 66 | 67 | if(Logger::Last() == NULL){ 68 | Add(newText); 69 | return; 70 | } 71 | 72 | string textAux[]; 73 | 74 | StringSplit(Logger::Last(), 62, textAux); 75 | StringTrimLeft(textAux[1]); 76 | StringTrimRight(textAux[1]); 77 | 78 | if (text != textAux[1]) 79 | { 80 | Add(newText); 81 | } 82 | 83 | } 84 | 85 | string Get(){ 86 | 87 | string logs = ""; 88 | 89 | for(int i = 0; i < ArraySize(_logs); i++){ 90 | logs += _logs[i] + "\n"; 91 | } 92 | 93 | return logs; 94 | 95 | } 96 | 97 | string Get(int index){ 98 | return _logs[index]; 99 | } 100 | 101 | string First(){ 102 | return _logs[ArraySize(_logs) - 1]; 103 | } 104 | 105 | string Last(){ 106 | return _logs[0]; 107 | } 108 | 109 | bool HasChanges() 110 | { 111 | if(_hasChanges) 112 | { 113 | _hasChanges = false; 114 | return true; 115 | } 116 | 117 | return false; 118 | 119 | } 120 | 121 | 122 | }; -------------------------------------------------------------------------------- /Include/Files/FileTxt.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| FileTxt.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "File.mqh" 7 | //+------------------------------------------------------------------+ 8 | //| Class CFileTxt | 9 | //| Purpose: Class of operations with text files. | 10 | //| Derives from class CFile. | 11 | //+------------------------------------------------------------------+ 12 | class CFileTxt : public CFile 13 | { 14 | public: 15 | CFileTxt(void); 16 | ~CFileTxt(void); 17 | //--- methods for working with files 18 | int Open(const string file_name,const int open_flags); 19 | //--- methods to access data 20 | uint WriteString(const string value); 21 | string ReadString(void); 22 | }; 23 | //+------------------------------------------------------------------+ 24 | //| Constructor | 25 | //+------------------------------------------------------------------+ 26 | CFileTxt::CFileTxt(void) 27 | { 28 | } 29 | //+------------------------------------------------------------------+ 30 | //| Destructor | 31 | //+------------------------------------------------------------------+ 32 | CFileTxt::~CFileTxt(void) 33 | { 34 | } 35 | //+------------------------------------------------------------------+ 36 | //| Open the text file | 37 | //+------------------------------------------------------------------+ 38 | int CFileTxt::Open(const string file_name,const int open_flags) 39 | { 40 | return(CFile::Open(file_name,open_flags|FILE_TXT)); 41 | } 42 | //+------------------------------------------------------------------+ 43 | //| Writing string to file | 44 | //+------------------------------------------------------------------+ 45 | uint CFileTxt::WriteString(const string value) 46 | { 47 | //--- check handle 48 | if(m_handle!=INVALID_HANDLE) 49 | return(FileWriteString(m_handle,value)); 50 | //--- failure 51 | return(0); 52 | } 53 | //+------------------------------------------------------------------+ 54 | //| Reading string from file | 55 | //+------------------------------------------------------------------+ 56 | string CFileTxt::ReadString(void) 57 | { 58 | //--- check handle 59 | if(m_handle!=INVALID_HANDLE) 60 | return(FileReadString(m_handle)); 61 | //--- failure 62 | return(""); 63 | } 64 | //+------------------------------------------------------------------+ 65 | -------------------------------------------------------------------------------- /Include/Controls/Label.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Label.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndObj.mqh" 7 | #include 8 | //+------------------------------------------------------------------+ 9 | //| Class CLabel | 10 | //| Usage: control that is displayed by | 11 | //| the CChartObjectLabel object | 12 | //+------------------------------------------------------------------+ 13 | class CLabel : public CWndObj 14 | { 15 | private: 16 | CChartObjectLabel m_label; // chart object 17 | 18 | public: 19 | CLabel(void); 20 | ~CLabel(void); 21 | //--- create 22 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 23 | 24 | protected: 25 | //--- handlers of object settings 26 | virtual bool OnSetText(void) { return(m_label.Description(m_text)); } 27 | virtual bool OnSetColor(void) { return(m_label.Color(m_color)); } 28 | virtual bool OnSetFont(void) { return(m_label.Font(m_font)); } 29 | virtual bool OnSetFontSize(void) { return(m_label.FontSize(m_font_size)); } 30 | //--- internal event handlers 31 | virtual bool OnCreate(void); 32 | virtual bool OnShow(void); 33 | virtual bool OnHide(void); 34 | virtual bool OnMove(void); 35 | }; 36 | //+------------------------------------------------------------------+ 37 | //| Constructor | 38 | //+------------------------------------------------------------------+ 39 | CLabel::CLabel(void) 40 | { 41 | m_color=CONTROLS_LABEL_COLOR; 42 | } 43 | //+------------------------------------------------------------------+ 44 | //| Destructor | 45 | //+------------------------------------------------------------------+ 46 | CLabel::~CLabel(void) 47 | { 48 | } 49 | //+------------------------------------------------------------------+ 50 | //| Create a control | 51 | //+------------------------------------------------------------------+ 52 | bool CLabel::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 53 | { 54 | //--- call method of the parent class 55 | if(!CWndObj::Create(chart,name,subwin,x1,y1,x2,y2)) 56 | return(false); 57 | //--- create the chart object 58 | if(!m_label.Create(chart,name,subwin,x1,y1)) 59 | return(false); 60 | //--- call the settings handler 61 | return(OnChange()); 62 | } 63 | //+------------------------------------------------------------------+ 64 | //| Create object on chart | 65 | //+------------------------------------------------------------------+ 66 | bool CLabel::OnCreate(void) 67 | { 68 | //--- create the chart object by previously set parameters 69 | return(m_label.Create(m_chart_id,m_name,m_subwin,m_rect.left,m_rect.top)); 70 | } 71 | //+------------------------------------------------------------------+ 72 | //| Display object on chart | 73 | //+------------------------------------------------------------------+ 74 | bool CLabel::OnShow(void) 75 | { 76 | return(m_label.Timeframes(OBJ_ALL_PERIODS)); 77 | } 78 | //+------------------------------------------------------------------+ 79 | //| Hide object from chart | 80 | //+------------------------------------------------------------------+ 81 | bool CLabel::OnHide(void) 82 | { 83 | return(m_label.Timeframes(OBJ_NO_PERIODS)); 84 | } 85 | //+------------------------------------------------------------------+ 86 | //| Absolute movement of the chart object | 87 | //+------------------------------------------------------------------+ 88 | bool CLabel::OnMove(void) 89 | { 90 | //--- position the chart object 91 | return(m_label.X_Distance(m_rect.left) && m_label.Y_Distance(m_rect.top)); 92 | } 93 | //+------------------------------------------------------------------+ 94 | -------------------------------------------------------------------------------- /Include/Controls/Picture.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Picture.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndObj.mqh" 7 | #include 8 | //+------------------------------------------------------------------+ 9 | //| Class CPicture | 10 | //| Note: image displayed by | 11 | //| the CChartObjectBmpLabel object | 12 | //+------------------------------------------------------------------+ 13 | class CPicture : public CWndObj 14 | { 15 | private: 16 | CChartObjectBmpLabel m_picture; // chart object 17 | //--- parameters of the chart object 18 | int m_border; // border width 19 | string m_bmp_name; // filename 20 | 21 | public: 22 | CPicture(void); 23 | ~CPicture(void); 24 | //--- create 25 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 26 | //--- parameters of the chart object 27 | int Border(void) const { return(m_border); } 28 | bool Border(const int value); 29 | string BmpName(void) const { return(m_bmp_name); } 30 | bool BmpName(const string name); 31 | 32 | protected: 33 | //--- internal event handlers 34 | virtual bool OnCreate(void); 35 | virtual bool OnShow(void); 36 | virtual bool OnHide(void); 37 | virtual bool OnMove(void); 38 | virtual bool OnChange(void); 39 | }; 40 | //+------------------------------------------------------------------+ 41 | //| Constructor | 42 | //+------------------------------------------------------------------+ 43 | CPicture::CPicture(void) : m_border(0), 44 | m_bmp_name(NULL) 45 | { 46 | } 47 | //+------------------------------------------------------------------+ 48 | //| Destructor | 49 | //+------------------------------------------------------------------+ 50 | CPicture::~CPicture(void) 51 | { 52 | } 53 | //+------------------------------------------------------------------+ 54 | //| Create a control | 55 | //+------------------------------------------------------------------+ 56 | bool CPicture::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 57 | { 58 | //--- call method of the parent class 59 | if(!CWndObj::Create(chart,name,subwin,x1,y1,x2,y2)) 60 | return(false); 61 | //--- create the chart object 62 | if(!m_picture.Create(chart,name,subwin,x1,y1)) 63 | return(false); 64 | //--- call the settings handler 65 | return(OnChange()); 66 | } 67 | //+------------------------------------------------------------------+ 68 | //| Set border width | 69 | //+------------------------------------------------------------------+ 70 | bool CPicture::Border(const int value) 71 | { 72 | //--- save new value of parameter 73 | m_border=value; 74 | //--- set up the chart object 75 | return(m_picture.Width(value)); 76 | } 77 | //+------------------------------------------------------------------+ 78 | //| Set image | 79 | //+------------------------------------------------------------------+ 80 | bool CPicture::BmpName(const string name) 81 | { 82 | //--- save new value of parameter 83 | m_bmp_name=name; 84 | //--- set up the chart object 85 | return(m_picture.BmpFileOn(name)); 86 | } 87 | //+------------------------------------------------------------------+ 88 | //| Create object on chart | 89 | //+------------------------------------------------------------------+ 90 | bool CPicture::OnCreate(void) 91 | { 92 | //--- create the chart object by previously set parameters 93 | return(m_picture.Create(m_chart_id,m_name,m_subwin,m_rect.left,m_rect.top)); 94 | } 95 | //+------------------------------------------------------------------+ 96 | //| Display object on chart | 97 | //+------------------------------------------------------------------+ 98 | bool CPicture::OnShow(void) 99 | { 100 | return(m_picture.Timeframes(OBJ_ALL_PERIODS)); 101 | } 102 | //+------------------------------------------------------------------+ 103 | //| Hide object from chart | 104 | //+------------------------------------------------------------------+ 105 | bool CPicture::OnHide(void) 106 | { 107 | return(m_picture.Timeframes(OBJ_NO_PERIODS)); 108 | } 109 | //+------------------------------------------------------------------+ 110 | //| Absolute movement of the chart object | 111 | //+------------------------------------------------------------------+ 112 | bool CPicture::OnMove(void) 113 | { 114 | //--- position the chart object 115 | return(m_picture.X_Distance(m_rect.left) && m_picture.Y_Distance(m_rect.top)); 116 | } 117 | //+------------------------------------------------------------------+ 118 | //| Set up the chart object | 119 | //+------------------------------------------------------------------+ 120 | bool CPicture::OnChange(void) 121 | { 122 | //--- set up the chart object 123 | return(m_picture.Width(m_border) && m_picture.BmpFileOn(m_bmp_name)); 124 | } 125 | //+------------------------------------------------------------------+ 126 | -------------------------------------------------------------------------------- /Include/Controls/Panel.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Panel.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndObj.mqh" 7 | #include 8 | //+------------------------------------------------------------------+ 9 | //| Class CPanel | 10 | //| Usage: control that is displayed by | 11 | //| the CChartObjectRectLabel object | 12 | //+------------------------------------------------------------------+ 13 | class CPanel : public CWndObj 14 | { 15 | private: 16 | CChartObjectRectLabel m_rectangle; // chart object 17 | //--- parameters of the chart object 18 | ENUM_BORDER_TYPE m_border; // border type 19 | 20 | public: 21 | CPanel(void); 22 | ~CPanel(void); 23 | //--- create 24 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 25 | //--- parameters of the chart object 26 | ENUM_BORDER_TYPE BorderType(void) const { return(m_border); } 27 | bool BorderType(const ENUM_BORDER_TYPE type); 28 | 29 | protected: 30 | //--- handlers of object settings 31 | virtual bool OnSetText(void) { return(m_rectangle.Description(m_text)); } 32 | virtual bool OnSetColorBackground(void) { return(m_rectangle.BackColor(m_color_background)); } 33 | virtual bool OnSetColorBorder(void) { return(m_rectangle.Color(m_color_border)); } 34 | //--- internal event handlers 35 | virtual bool OnCreate(void); 36 | virtual bool OnShow(void); 37 | virtual bool OnHide(void); 38 | virtual bool OnMove(void); 39 | virtual bool OnResize(void); 40 | virtual bool OnChange(void); 41 | }; 42 | //+------------------------------------------------------------------+ 43 | //| Constructor | 44 | //+------------------------------------------------------------------+ 45 | CPanel::CPanel(void) : m_border(BORDER_FLAT) 46 | { 47 | } 48 | //+------------------------------------------------------------------+ 49 | //| Destructor | 50 | //+------------------------------------------------------------------+ 51 | CPanel::~CPanel(void) 52 | { 53 | } 54 | //+------------------------------------------------------------------+ 55 | //| Create a control | 56 | //+------------------------------------------------------------------+ 57 | bool CPanel::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 58 | { 59 | //--- call method of the parent class 60 | if(!CWndObj::Create(chart,name,subwin,x1,y1,x2,y2)) 61 | return(false); 62 | //--- create the chart object 63 | if(!m_rectangle.Create(chart,name,subwin,x1,y1,Width(),Height())) 64 | return(false); 65 | //--- call the settings handler 66 | return(OnChange()); 67 | } 68 | //+------------------------------------------------------------------+ 69 | //| Set border type | 70 | //+------------------------------------------------------------------+ 71 | bool CPanel::BorderType(const ENUM_BORDER_TYPE type) 72 | { 73 | //--- save new value of parameter 74 | m_border=type; 75 | //--- set up the chart object 76 | return(m_rectangle.BorderType(type)); 77 | } 78 | //+------------------------------------------------------------------+ 79 | //| Create object on chart | 80 | //+------------------------------------------------------------------+ 81 | bool CPanel::OnCreate(void) 82 | { 83 | //--- create the chart object by previously set parameters 84 | return(m_rectangle.Create(m_chart_id,m_name,m_subwin,m_rect.left,m_rect.top,m_rect.Width(),m_rect.Height())); 85 | } 86 | //+------------------------------------------------------------------+ 87 | //| Display object on chart | 88 | //+------------------------------------------------------------------+ 89 | bool CPanel::OnShow(void) 90 | { 91 | return(m_rectangle.Timeframes(OBJ_ALL_PERIODS)); 92 | } 93 | //+------------------------------------------------------------------+ 94 | //| Hide object from chart | 95 | //+------------------------------------------------------------------+ 96 | bool CPanel::OnHide(void) 97 | { 98 | return(m_rectangle.Timeframes(OBJ_NO_PERIODS)); 99 | } 100 | //+------------------------------------------------------------------+ 101 | //| Absolute movement of the chart object | 102 | //+------------------------------------------------------------------+ 103 | bool CPanel::OnMove(void) 104 | { 105 | //--- position the chart object 106 | return(m_rectangle.X_Distance(m_rect.left) && m_rectangle.Y_Distance(m_rect.top)); 107 | } 108 | //+------------------------------------------------------------------+ 109 | //| Resize the chart object | 110 | //+------------------------------------------------------------------+ 111 | bool CPanel::OnResize(void) 112 | { 113 | //--- resize the chart object 114 | return(m_rectangle.X_Size(m_rect.Width()) && m_rectangle.Y_Size(m_rect.Height())); 115 | } 116 | //+------------------------------------------------------------------+ 117 | //| Set up the chart object | 118 | //+------------------------------------------------------------------+ 119 | bool CPanel::OnChange(void) 120 | { 121 | //--- set up the chart object 122 | return(CWndObj::OnChange() && m_rectangle.BorderType(m_border)); 123 | } 124 | //+------------------------------------------------------------------+ 125 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BadRobot Framework 2 | 3 | [![Package version](https://img.shields.io/github/release/erlonfs/bad-robot.framework.svg?style=flat-square)](https://github.com/erlonfs/bad-robot.framework/releases) 4 | [![Open Source Love png2](https://badges.frapsoft.com/os/v2/open-source.png?v=103)](https://github.com/erlonfs/bad-robot.framework/) 5 | [![GitHub license](https://img.shields.io/github/license/erlonfs/bad-robot.framework.svg)](https://github.com/erlonfs/bad-robot.framework/blob/master/LICENSE) 6 | [![Join the chat at Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bad-robot-framework/) 7 | 8 | [![GitHub stars](https://img.shields.io/github/stars/erlonfs/bad-robot.framework.svg?style=social)](https://github.com/erlonfs/bad-robot.framework/stargazers) 9 | [![GitHub watchers](https://img.shields.io/github/watchers/erlonfs/bad-robot.framework.svg?style=social)](https://github.com/erlonfs/bad-robot.framework/watchers) 10 | [![GitHub issues](https://img.shields.io/github/issues/erlonfs/bad-robot.framework.svg?style=social)](https://github.com/erlonfs/bad-robot.framework/issues) 11 | [![GitHub pulls](https://img.shields.io/github/issues-pr/erlonfs/bad-robot.framework.svg?style=social)](https://github.com/erlonfs/bad-robot.framework/pulls) 12 | ![GitHub forks](https://img.shields.io/github/forks/erlonfs/bad-robot.framework.svg?style=social) 13 | 14 | Um framework de criação de robôs traders, onde todas as [definições e gerenciamentos](#features) ficam por conta do BadRobot. Implemente apenas a estratégia sem se preocupar com o gerenciamento do trade. 15 | 16 | ## Getting Started 17 | 18 | Faça o [download](https://github.com/erlonfs/bad-robot.framework/archive/master.zip) do framework ou `git clone https://github.com/erlonfs/bad-robot.framework.git`. 19 | Copie ou clone o projeto dentro do diretorio de instalação do [metatrader 5](https://www.metatrader5.com/pt), na pasta MQL5. 20 | 21 | ### Prerequisites 22 | 23 | Ferramentas necessárias para desenvolvimento 24 | 25 | ``` 26 | Metatrader 5 27 | MetaEditor 5 28 | ``` 29 | 30 | ### Installing 31 | 32 | Execute o [metatrader 5](https://www.metatrader5.com/pt), acesse o editor de linguagem MetaQuotes (MetaEditor 5) ou pressione `f4` no terminal de negociação. Acesse o menu `Arquivo > Abrir diretório de dados`. Você está dentro do diretório da instalação do terminal, acesse a pasta `\MQL5`. Todo o codigo do framework deve ser baixado ou clonado aqui. 33 | 34 | ``` 35 | $ cd MQL5 36 | $ git clone https://github.com/erlonfs/bad-robot.framework.git 37 | ``` 38 | 39 | Até o momento temos o framework no diretório de desenvolvimento. O Proximo passo é repetir o procedimento para os robôs especificamente. O diretório onde eles deverão ser clonados será `\Experts`. 40 | 41 | Exemplo 42 | ``` 43 | $ cd Experts 44 | $ git clone https://github.com/erlonfs/first-candle.bad-robot.git 45 | ``` 46 | 47 | Apos isso, retorne ao editor de codigos, utilizado o navegador à esqueda para explorar o diretório de desenvolvimento, acesse a pasta `\Experts\first-candle.bad-robot`, e o arquivo `first_candle.mq5`. Compile o projeto ou pressione ``` F7 ```. 48 | 49 | Dessa forma estará sendo compilado o robô na versão de instalação do framework. Para versões mais atualizadas do BadRobot acesse https://github.com/erlonfs/bad-robot.framework/releases. Repita o procedimento para novas atualizaçôes do framework, necessitando apenas de uma nova compilação do robô. 50 | 51 | Veja como instalar utilizando o [git bash](install_from_git_bash.md) 52 | 53 | ### Features 54 | 55 | Funções e ferramentas que o framework oferece: 56 | 57 | | Função | Descrição | 58 | | ------ | ------ | 59 | |Stop Gain | Saída com lucro em uma operção | SIM | 60 | |Stop Loss | Saída com prejuizo máximo em uma operação | SIM| 61 | |Stop no candle anterior | Determina um novo stop loss a cada novo candlestick, que por sua vez é ajustado para a mínima do mesmo | SIM| 62 | |Horário de inicio e fim | Determina o hórario de início e término do robô | SIM| 63 | |Horário de intervalo | Determina um intervalo para pausa da execução da estratégia |SIM | 64 | |Trailing Stop | Quando ativado, ajusta o stop loss de acordo com o movimento e avanço da preço a favor na operação, ajustando assim o mesmo de acordo com a definição do usuário |SIM| 65 | |Break-even | Habilita o ponto de equilibrio, de acordo com a definição do usuário |SIM| 66 | |Saída Parcial | De acordo com as saídas configuradas, ocorre a realizacao parcial da posição, garantindo parte do lucro caso a operação volte contra a posição |SIM| 67 | |Gerenciamento Financeiro | Habilita o gerenciamento financeiro diário do robô, caso necessite determinar uma parada por atingir um valor de prejuizo máximo diário | SIM| 68 | |Notificações no App MT5 | Envia notificações para o app [metatrader5](https://play.google.com/store/apps/details?id=net.metaquotes.metatrader5&hl=pt_BR) para android (disponivel na play store) |SIM| 69 | 70 | Para comecar um novo projeto, pode se utilizar o exemplo [sample.bad-robot](https://github.com/erlonfs/sample.bad-robot). Pois ele já possui uma estrutura com uso do framework, faltando apenas a codificação da estratégia. 71 | 72 | ## Running the tests 73 | 74 | Por limitações da linguagem [mql5](https://www.mql5.com/pt), ainda não possui testes unitários implementados no framework. Utiliza backtest do metatrader5 e técnicas de debugging. 75 | 76 | ## Deployment 77 | 78 | Ao compilar o robô, um arquivo com mesmo nome `first_candle.mq5`, mas com extensão `.ex5` estará no diretório do mesmo. Ficando assim: 79 | ``` 80 | first_candle.ex5 81 | ``` 82 | 83 | Esse será o executável do robô. De volta ao [metatrader 5](https://www.metatrader5.com/pt), no navegador `Exibir\Navegador` (```CTRL+N ```), no grupo `Consultor expert` estará o robô, pronto para uso. 84 | 85 | ## Contributing 86 | 87 | Entre em contato pra discutirmos novas idéias e então é so submeter um pull request. 88 | 89 | ## Versioning 90 | 91 | Nós utilizamos [SemVer](http://semver.org/) para versionamento. Para versões disponiveis, acesse [tags on this repository](https://github.com/erlonfs/bad-robot.framework/tags). 92 | 93 | ## Authors 94 | 95 | * **Erlon F Souza** - *Idealizador* - [erlonfs](https://github.com/erlonfs) 96 | 97 | Veja também a lista de [contribuidores](https://github.com/erlonfs/bad-robot.framework/graphs/contributors) Participantes do projeto. 98 | 99 | ## License 100 | 101 | Este projeto é licenciado sob a MIT License - veja em [LICENSE](LICENSE) para mais detalhes 102 | 103 | ## See more 104 | 105 | Veja outros robôs desenvolvidos utlizando o framework 106 | 107 | * https://github.com/erlonfs/first-candle.bad-robot 108 | * https://github.com/erlonfs/box.bad-robot 109 | * https://github.com/erlonfs/elephant-walk.bad-robot 110 | * https://github.com/erlonfs/line.bad-robot 111 | 112 | -------------------------------------------------------------------------------- /Include/Arrays/TreeNode.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| TreeNode.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include 7 | //+------------------------------------------------------------------+ 8 | //| Class CTreeNode. | 9 | //| Purpose: Base class of node of binary tree CTree. | 10 | //| Derives from class CObject. | 11 | //+------------------------------------------------------------------+ 12 | class CTreeNode : public CObject 13 | { 14 | private: 15 | CTreeNode *m_p_node; // link to node up 16 | CTreeNode *m_l_node; // link to node left 17 | CTreeNode *m_r_node; // link to node right 18 | //--- variables 19 | int m_balance; // balance of node 20 | int m_l_balance; // balance of the left branch 21 | int m_r_balance; // balance of the right branch 22 | 23 | public: 24 | CTreeNode(void); 25 | ~CTreeNode(void); 26 | //--- methods of access to protected data 27 | CTreeNode* Parent(void) const { return(m_p_node); } 28 | void Parent(CTreeNode *node) { m_p_node=node; } 29 | CTreeNode* Left(void) const { return(m_l_node); } 30 | void Left(CTreeNode *node) { m_l_node=node; } 31 | CTreeNode* Right(void) const { return(m_r_node); } 32 | void Right(CTreeNode *node) { m_r_node=node; } 33 | int Balance(void) const { return(m_balance); } 34 | int BalanceL(void) const { return(m_l_balance); } 35 | int BalanceR(void) const { return(m_r_balance); } 36 | //--- method of identifying the object 37 | virtual int Type(void) const { return(0x8888); } 38 | //--- methods for controlling 39 | int RefreshBalance(void); 40 | CTreeNode *GetNext(const CTreeNode *node); 41 | //--- methods for working with files 42 | bool SaveNode(const int file_handle); 43 | bool LoadNode(const int file_handle,CTreeNode *main); 44 | 45 | protected: 46 | //--- method for creating an instance of class 47 | virtual CTreeNode *CreateSample(void) { return(NULL); } 48 | }; 49 | //+------------------------------------------------------------------+ 50 | //| Constructor | 51 | //+------------------------------------------------------------------+ 52 | CTreeNode::CTreeNode(void) : m_p_node(NULL), 53 | m_l_node(NULL), 54 | m_r_node(NULL), 55 | m_balance(0), 56 | m_l_balance(0), 57 | m_r_balance(0) 58 | { 59 | } 60 | //+------------------------------------------------------------------+ 61 | //| Destructor | 62 | //+------------------------------------------------------------------+ 63 | CTreeNode::~CTreeNode(void) 64 | { 65 | //--- delete nodes of the next level 66 | if(m_l_node!=NULL) 67 | delete m_l_node; 68 | if(m_r_node!=NULL) 69 | delete m_r_node; 70 | } 71 | //+------------------------------------------------------------------+ 72 | //| Calculating the balance of the node | 73 | //+------------------------------------------------------------------+ 74 | int CTreeNode::RefreshBalance(void) 75 | { 76 | //--- calculate the balance of the left branch 77 | if(m_l_node==NULL) 78 | m_l_balance=0; 79 | else 80 | m_l_balance=m_l_node.RefreshBalance(); 81 | //--- calculate the balance of the right branch 82 | if(m_r_node==NULL) 83 | m_r_balance=0; 84 | else 85 | m_r_balance=m_r_node.RefreshBalance(); 86 | //--- calculate the balance of the node 87 | if(m_r_balance>m_l_balance) 88 | m_balance=m_r_balance+1; 89 | else 90 | m_balance=m_l_balance+1; 91 | //--- result 92 | return(m_balance); 93 | } 94 | //+------------------------------------------------------------------+ 95 | //| Selecting next node | 96 | //+------------------------------------------------------------------+ 97 | CTreeNode *CTreeNode::GetNext(const CTreeNode *node) 98 | { 99 | if(Compare(node)>0) 100 | return(m_l_node); 101 | //--- result 102 | return(m_r_node); 103 | } 104 | //+------------------------------------------------------------------+ 105 | //| Writing node data to file | 106 | //+------------------------------------------------------------------+ 107 | bool CTreeNode::SaveNode(const int file_handle) 108 | { 109 | bool result=true; 110 | //--- check 111 | if(file_handle==INVALID_HANDLE) 112 | return(false); 113 | //--- write left node (if it is available) 114 | if(m_l_node!=NULL) 115 | { 116 | FileWriteInteger(file_handle,'L',SHORT_VALUE); 117 | result&=m_l_node.SaveNode(file_handle); 118 | } 119 | else 120 | FileWriteInteger(file_handle,'X',SHORT_VALUE); 121 | //--- write data of current node 122 | result&=Save(file_handle); 123 | //--- write right node (if it is available) 124 | if(m_r_node!=NULL) 125 | { 126 | FileWriteInteger(file_handle,'R',SHORT_VALUE); 127 | result&=m_r_node.SaveNode(file_handle); 128 | } 129 | else 130 | FileWriteInteger(file_handle,'X',SHORT_VALUE); 131 | //--- successful 132 | return(true); 133 | } 134 | //+------------------------------------------------------------------+ 135 | //| Reading node data from file | 136 | //+------------------------------------------------------------------+ 137 | bool CTreeNode::LoadNode(const int file_handle,CTreeNode *main) 138 | { 139 | bool result=true; 140 | short s_val; 141 | CTreeNode *node; 142 | //--- check 143 | if(file_handle==INVALID_HANDLE) 144 | return(false); 145 | //--- read directions 146 | s_val=(short)FileReadInteger(file_handle,SHORT_VALUE); 147 | if(s_val=='L') 148 | { 149 | //--- read left node (if there is data) 150 | node=CreateSample(); 151 | if(node==NULL) 152 | return(false); 153 | m_l_node=node; 154 | node.Parent(main); 155 | result&=node.LoadNode(file_handle,node); 156 | } 157 | //--- read data of current node 158 | result&=Load(file_handle); 159 | //--- read directions 160 | s_val=(short)FileReadInteger(file_handle,SHORT_VALUE); 161 | if(s_val=='R') 162 | { 163 | //--- read right node (if there is data) 164 | node=CreateSample(); 165 | if(node==NULL) 166 | return(false); 167 | m_r_node=node; 168 | node.Parent(main); 169 | result&=node.LoadNode(file_handle,node); 170 | } 171 | //--- result 172 | return(result); 173 | } 174 | //+------------------------------------------------------------------+ 175 | -------------------------------------------------------------------------------- /Include/Controls/RadioButton.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| RadioButton.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndContainer.mqh" 7 | #include "BmpButton.mqh" 8 | #include "Edit.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Resources | 11 | //+------------------------------------------------------------------+ 12 | #resource "res\\RadioButtonOn.bmp" 13 | #resource "res\\RadioButtonOff.bmp" 14 | //+------------------------------------------------------------------+ 15 | //| Class CRadioButton | 16 | //| Usage: class that implements the "RadioButton" control | 17 | //+------------------------------------------------------------------+ 18 | class CRadioButton : public CWndContainer 19 | { 20 | private: 21 | //--- dependent controls 22 | CBmpButton m_button; // button object 23 | CEdit m_label; // label object 24 | 25 | public: 26 | CRadioButton(void); 27 | ~CRadioButton(void); 28 | //--- create 29 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 30 | //--- chart event handler 31 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 32 | //--- settings 33 | string Text(void) const { return(m_label.Text()); } 34 | bool Text(const string value) { return(m_label.Text(value)); } 35 | color Color(void) const { return(m_label.Color()); } 36 | bool Color(const color value) { return(m_label.Color(value)); } 37 | //--- state 38 | bool State(void) const { return(m_button.Pressed()); } 39 | bool State(const bool flag) { return(m_button.Pressed(flag)); } 40 | 41 | protected: 42 | //--- create dependent controls 43 | virtual bool CreateButton(void); 44 | virtual bool CreateLabel(void); 45 | //--- handlers of the dependent controls events 46 | virtual bool OnClickButton(void); 47 | virtual bool OnClickLabel(void); 48 | }; 49 | //+------------------------------------------------------------------+ 50 | //| Common handler of chart events | 51 | //+------------------------------------------------------------------+ 52 | EVENT_MAP_BEGIN(CRadioButton) 53 | ON_EVENT(ON_CLICK,m_button,OnClickButton) 54 | ON_EVENT(ON_CLICK,m_label,OnClickLabel) 55 | EVENT_MAP_END(CWndContainer) 56 | //+------------------------------------------------------------------+ 57 | //| Constructor | 58 | //+------------------------------------------------------------------+ 59 | CRadioButton::CRadioButton(void) 60 | { 61 | } 62 | //+------------------------------------------------------------------+ 63 | //| Destructor | 64 | //+------------------------------------------------------------------+ 65 | CRadioButton::~CRadioButton(void) 66 | { 67 | } 68 | //+------------------------------------------------------------------+ 69 | //| Create a control | 70 | //+------------------------------------------------------------------+ 71 | bool CRadioButton::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 72 | { 73 | //--- call method of the parent class 74 | if(!CWndContainer::Create(chart,name,subwin,x1,y1,x2,y2)) 75 | return(false); 76 | //--- create dependent controls 77 | if(!CreateButton()) 78 | return(false); 79 | if(!CreateLabel()) 80 | return(false); 81 | //--- succeeded 82 | return(true); 83 | } 84 | //+------------------------------------------------------------------+ 85 | //| Create button | 86 | //+------------------------------------------------------------------+ 87 | bool CRadioButton::CreateButton(void) 88 | { 89 | //--- calculate coordinates 90 | int x1=CONTROLS_RADIO_BUTTON_X_OFF; 91 | int y1=CONTROLS_RADIO_BUTTON_Y_OFF; 92 | int x2=x1+CONTROLS_BUTTON_SIZE; 93 | int y2=y1+CONTROLS_BUTTON_SIZE-CONTROLS_BORDER_WIDTH; 94 | //--- create 95 | if(!m_button.Create(m_chart_id,m_name+"Button",m_subwin,x1,y1,x2,y2)) 96 | return(false); 97 | if(!m_button.BmpNames("::res\\RadioButtonOff.bmp","::res\\RadioButtonOn.bmp")) 98 | return(false); 99 | if(!Add(m_button)) 100 | return(false); 101 | m_button.Locking(true); 102 | //--- succeeded 103 | return(true); 104 | } 105 | //+------------------------------------------------------------------+ 106 | //| Create label | 107 | //+------------------------------------------------------------------+ 108 | bool CRadioButton::CreateLabel(void) 109 | { 110 | //--- calculate coordinates 111 | int x1=CONTROLS_RADIO_LABEL_X_OFF; 112 | int y1=CONTROLS_RADIO_LABEL_Y_OFF; 113 | int x2=Width(); 114 | int y2=Height(); 115 | //--- create 116 | if(!m_label.Create(m_chart_id,m_name+"Label",m_subwin,x1,y1,x2,y2)) 117 | return(false); 118 | if(!m_label.Text(m_name)) 119 | return(false); 120 | if(!Add(m_label)) 121 | return(false); 122 | m_label.ReadOnly(true); 123 | m_label.ColorBackground(CONTROLS_CHECKGROUP_COLOR_BG); 124 | m_label.ColorBorder(CONTROLS_CHECKGROUP_COLOR_BG); 125 | //--- succeeded 126 | return(true); 127 | } 128 | //+------------------------------------------------------------------+ 129 | //| Handler of click on button | 130 | //+------------------------------------------------------------------+ 131 | bool CRadioButton::OnClickButton(void) 132 | { 133 | //--- if button is in the "turned off" state, turn it on again and complete the handling 134 | //--- this is due to that radio button can not be turned off by clicking on it (it can be only turned on) 135 | if(!m_button.Pressed()) 136 | { 137 | //--- turn on the radio button 138 | if(!m_button.Pressed(true)) 139 | return(false); 140 | } 141 | //--- send the "changed state" event 142 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_CHANGE,m_id,0.0,m_name); 143 | //--- handled 144 | return(true); 145 | } 146 | //+------------------------------------------------------------------+ 147 | //| Handler of click on label | 148 | //+------------------------------------------------------------------+ 149 | bool CRadioButton::OnClickLabel(void) 150 | { 151 | //--- if button is in the "turned on" state, simply complete the handling 152 | //--- this is due to that radio button can not be turned off by clicking on it (it can be only turned on) 153 | if(m_button.Pressed()) 154 | return(true); 155 | //--- turn on the radio button 156 | m_button.Pressed(true); 157 | //--- return the result of the button click handler 158 | return(OnClickButton()); 159 | } 160 | //+------------------------------------------------------------------+ 161 | -------------------------------------------------------------------------------- /Include/Arrays/Array.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Array.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include 7 | //+------------------------------------------------------------------+ 8 | //| Class CArray | 9 | //| Purpose: Base class of dynamic arrays. | 10 | //| Derives from class CObject. | 11 | //+------------------------------------------------------------------+ 12 | class CArray : public CObject 13 | { 14 | protected: 15 | int m_step_resize; // increment size of the array 16 | int m_data_total; // number of elements 17 | int m_data_max; // maximmum size of the array without memory reallocation 18 | int m_sort_mode; // mode of array sorting 19 | 20 | public: 21 | CArray(void); 22 | ~CArray(void); 23 | //--- methods of access to protected data 24 | int Step(void) const { return(m_step_resize); } 25 | bool Step(const int step); 26 | int Total(void) const { return(m_data_total); } 27 | int Available(void) const { return(m_data_max-m_data_total); } 28 | int Max(void) const { return(m_data_max); } 29 | bool IsSorted(const int mode=0) const { return(m_sort_mode==mode); } 30 | int SortMode(void) const { return(m_sort_mode); } 31 | //--- cleaning method 32 | void Clear(void) { m_data_total=0; } 33 | //--- methods for working with files 34 | virtual bool Save(const int file_handle); 35 | virtual bool Load(const int file_handle); 36 | //--- sorting method 37 | void Sort(const int mode=0); 38 | 39 | protected: 40 | virtual void QuickSort(int beg,int end,const int mode=0) { m_sort_mode=-1; } 41 | //--- templates for methods of searching for minimum and maximum 42 | template 43 | int Minimum(const T &data[],const int start,const int count) const; 44 | template 45 | int Maximum(const T &data[],const int start,const int count) const; 46 | }; 47 | //+------------------------------------------------------------------+ 48 | //| Constructor | 49 | //+------------------------------------------------------------------+ 50 | CArray::CArray(void) : m_step_resize(16), 51 | m_data_total(0), 52 | m_data_max(0), 53 | m_sort_mode(-1) 54 | { 55 | } 56 | //+------------------------------------------------------------------+ 57 | //| Destructor | 58 | //+------------------------------------------------------------------+ 59 | CArray::~CArray(void) 60 | { 61 | } 62 | //+------------------------------------------------------------------+ 63 | //| Method Set for variable m_step_resize | 64 | //+------------------------------------------------------------------+ 65 | bool CArray::Step(const int step) 66 | { 67 | //--- check 68 | if(step>0) 69 | { 70 | m_step_resize=step; 71 | return(true); 72 | } 73 | //--- failure 74 | return(false); 75 | } 76 | //+------------------------------------------------------------------+ 77 | //| Sorting an array in ascending order | 78 | //+------------------------------------------------------------------+ 79 | void CArray::Sort(const int mode) 80 | { 81 | //--- check 82 | if(IsSorted(mode)) 83 | return; 84 | m_sort_mode=mode; 85 | if(m_data_total<=1) 86 | return; 87 | //--- sort 88 | QuickSort(0,m_data_total-1,mode); 89 | } 90 | //+------------------------------------------------------------------+ 91 | //| Writing header of array to file | 92 | //+------------------------------------------------------------------+ 93 | bool CArray::Save(const int file_handle) 94 | { 95 | //--- check handle 96 | if(file_handle!=INVALID_HANDLE) 97 | { 98 | //--- write start marker - 0xFFFFFFFFFFFFFFFF 99 | if(FileWriteLong(file_handle,-1)==sizeof(long)) 100 | { 101 | //--- write array type 102 | if(FileWriteInteger(file_handle,Type(),INT_VALUE)==INT_VALUE) 103 | return(true); 104 | } 105 | } 106 | //--- failure 107 | return(false); 108 | } 109 | //+------------------------------------------------------------------+ 110 | //| Reading header of array from file | 111 | //+------------------------------------------------------------------+ 112 | bool CArray::Load(const int file_handle) 113 | { 114 | //--- check handle 115 | if(file_handle!=INVALID_HANDLE) 116 | { 117 | //--- read and check start marker - 0xFFFFFFFFFFFFFFFF 118 | if(FileReadLong(file_handle)==-1) 119 | { 120 | //--- read and check array type 121 | if(FileReadInteger(file_handle,INT_VALUE)==Type()) 122 | return(true); 123 | } 124 | } 125 | //--- failure 126 | return(false); 127 | } 128 | //+------------------------------------------------------------------+ 129 | //| Find minimum of array | 130 | //+------------------------------------------------------------------+ 131 | template 132 | int CArray::Minimum(const T &data[],const int start,const int count) const 133 | { 134 | int real_count; 135 | //--- check for empty array 136 | if(m_data_total<1) 137 | { 138 | SetUserError(ERR_USER_ARRAY_IS_EMPTY); 139 | return(-1); 140 | } 141 | //--- check for start is out of range 142 | if(start<0 || start>=m_data_total) 143 | { 144 | SetUserError(ERR_USER_ITEM_NOT_FOUND); 145 | return(-1); 146 | } 147 | //--- compute count of elements 148 | real_count=(count==WHOLE_ARRAY || start+count>m_data_total) ? m_data_total-start : count; 149 | #ifdef __MQL5__ 150 | return(ArrayMinimum(data,start,real_count)); 151 | #else 152 | return(ArrayMinimum(data,real_count,start)); 153 | #endif 154 | } 155 | //+------------------------------------------------------------------+ 156 | //| Find maximum of array | 157 | //+------------------------------------------------------------------+ 158 | template 159 | int CArray::Maximum(const T &data[],const int start,const int count) const 160 | { 161 | int real_count; 162 | //--- check for empty array 163 | if(m_data_total<1) 164 | { 165 | SetUserError(ERR_USER_ARRAY_IS_EMPTY); 166 | return(-1); 167 | } 168 | //--- check for start is out of range 169 | if(start<0 || start>=m_data_total) 170 | { 171 | SetUserError(ERR_USER_ITEM_NOT_FOUND); 172 | return(-1); 173 | } 174 | //--- compute count of elements 175 | real_count=(count==WHOLE_ARRAY || start+count>m_data_total) ? m_data_total-start : count; 176 | #ifdef __MQL5__ 177 | return(ArrayMaximum(data,start,real_count)); 178 | #else 179 | return(ArrayMaximum(data,real_count,start)); 180 | #endif 181 | } 182 | //+------------------------------------------------------------------+ 183 | -------------------------------------------------------------------------------- /Include/ChartObjects/ChartObjectsShapes.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| ChartObjectsShapes.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | //| All shapes. | 7 | //+------------------------------------------------------------------+ 8 | #include "ChartObject.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Class CChartObjectRectangle. | 11 | //| Purpose: Class of the "Rectangle" object of chart. | 12 | //| Derives from class CChartObject. | 13 | //+------------------------------------------------------------------+ 14 | class CChartObjectRectangle : public CChartObject 15 | { 16 | public: 17 | CChartObjectRectangle(void); 18 | ~CChartObjectRectangle(void); 19 | //--- method of creating the object 20 | bool Create(long chart_id,const string name,const int window, 21 | const datetime time1,const double price1, 22 | const datetime time2,const double price2); 23 | //--- method of identifying the object 24 | virtual int Type(void) const { return(OBJ_RECTANGLE); } 25 | }; 26 | //+------------------------------------------------------------------+ 27 | //| Constructor | 28 | //+------------------------------------------------------------------+ 29 | CChartObjectRectangle::CChartObjectRectangle(void) 30 | { 31 | } 32 | //+------------------------------------------------------------------+ 33 | //| Destructor | 34 | //+------------------------------------------------------------------+ 35 | CChartObjectRectangle::~CChartObjectRectangle(void) 36 | { 37 | } 38 | //+------------------------------------------------------------------+ 39 | //| Create object "Rectangle" | 40 | //+------------------------------------------------------------------+ 41 | bool CChartObjectRectangle::Create(long chart_id,const string name,const int window, 42 | const datetime time1,const double price1, 43 | const datetime time2,const double price2) 44 | { 45 | if(!ObjectCreate(chart_id,name,OBJ_RECTANGLE,window,time1,price1,time2,price2)) 46 | return(false); 47 | if(!Attach(chart_id,name,window,2)) 48 | return(false); 49 | //--- successful 50 | return(true); 51 | } 52 | //+------------------------------------------------------------------+ 53 | //| Class CChartObjectTriangle. | 54 | //| Purpose: Class of the "Triangle" object of chart. | 55 | //| Derives from class CChartObject. | 56 | //+------------------------------------------------------------------+ 57 | class CChartObjectTriangle : public CChartObject 58 | { 59 | public: 60 | CChartObjectTriangle(void); 61 | ~CChartObjectTriangle(void); 62 | //--- method of creating the object 63 | bool Create(long chart_id,const string name,const int window, 64 | const datetime time1,const double price1, 65 | const datetime time2,const double price2, 66 | const datetime time3,const double price3); 67 | //--- method of identifying the object 68 | virtual int Type(void) const { return(OBJ_TRIANGLE); } 69 | }; 70 | //+------------------------------------------------------------------+ 71 | //| Constructor | 72 | //+------------------------------------------------------------------+ 73 | CChartObjectTriangle::CChartObjectTriangle(void) 74 | { 75 | } 76 | //+------------------------------------------------------------------+ 77 | //| Destructor | 78 | //+------------------------------------------------------------------+ 79 | CChartObjectTriangle::~CChartObjectTriangle(void) 80 | { 81 | } 82 | //+------------------------------------------------------------------+ 83 | //| Create object "Triangle" | 84 | //+------------------------------------------------------------------+ 85 | bool CChartObjectTriangle::Create(long chart_id,const string name,const int window, 86 | const datetime time1,const double price1, 87 | const datetime time2,const double price2, 88 | const datetime time3,const double price3) 89 | { 90 | if(!ObjectCreate(chart_id,name,OBJ_TRIANGLE,window,time1,price1,time2,price2,time3,price3)) 91 | return(false); 92 | if(!Attach(chart_id,name,window,3)) 93 | return(false); 94 | //--- successful 95 | return(true); 96 | } 97 | //+------------------------------------------------------------------+ 98 | //| Class CChartObjectEllipse. | 99 | //| Purpose: Class of the "Ellipse" object of chart. | 100 | //| Derives from class CChartObject. | 101 | //+------------------------------------------------------------------+ 102 | class CChartObjectEllipse : public CChartObject 103 | { 104 | public: 105 | CChartObjectEllipse(void); 106 | ~CChartObjectEllipse(void); 107 | //--- method of creating the object 108 | bool Create(long chart_id,const string name,const int window, 109 | const datetime time1,const double price1, 110 | const datetime time2,const double price2, 111 | const datetime time3,const double price3); 112 | //--- method of identifying the object 113 | virtual int Type(void) const { return(OBJ_ELLIPSE); } 114 | }; 115 | //+------------------------------------------------------------------+ 116 | //| Constructor | 117 | //+------------------------------------------------------------------+ 118 | CChartObjectEllipse::CChartObjectEllipse(void) 119 | { 120 | } 121 | //+------------------------------------------------------------------+ 122 | //| Destructor | 123 | //+------------------------------------------------------------------+ 124 | CChartObjectEllipse::~CChartObjectEllipse(void) 125 | { 126 | } 127 | //+------------------------------------------------------------------+ 128 | //| Create object "Ellipse" | 129 | //+------------------------------------------------------------------+ 130 | bool CChartObjectEllipse::Create(long chart_id,const string name,const int window, 131 | const datetime time1,const double price1, 132 | const datetime time2,const double price2, 133 | const datetime time3,const double price3) 134 | { 135 | if(!ObjectCreate(chart_id,name,OBJ_ELLIPSE,window,time1,price1,time2,price2,time3,price3)) 136 | return(false); 137 | if(!Attach(chart_id,name,window,3)) 138 | return(false); 139 | //--- successful 140 | return(true); 141 | } 142 | //+------------------------------------------------------------------+ 143 | -------------------------------------------------------------------------------- /Include/Controls/CheckBox.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| CheckBox.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndContainer.mqh" 7 | #include "BmpButton.mqh" 8 | #include "Edit.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Resources | 11 | //+------------------------------------------------------------------+ 12 | #resource "res\\CheckBoxOn.bmp" 13 | #resource "res\\CheckBoxOff.bmp" 14 | //+------------------------------------------------------------------+ 15 | //| Class CCheckBox | 16 | //| Usage: class that implements the "CheckBox" control | 17 | //+------------------------------------------------------------------+ 18 | class CCheckBox : public CWndContainer 19 | { 20 | private: 21 | //--- dependent controls 22 | CBmpButton m_button; // button object 23 | CEdit m_label; // label object 24 | //--- data 25 | int m_value; // value 26 | 27 | public: 28 | CCheckBox(void); 29 | ~CCheckBox(void); 30 | //--- create 31 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 32 | //--- chart event handler 33 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 34 | //--- settings 35 | string Text(void) const { return(m_label.Text()); } 36 | bool Text(const string value) { return(m_label.Text(value)); } 37 | color Color(void) const { return(m_label.Color()); } 38 | bool Color(const color value) { return(m_label.Color(value)); } 39 | //--- state 40 | bool Checked(void) const { return(m_button.Pressed()); } 41 | bool Checked(const bool flag) { return(m_button.Pressed(flag)); } 42 | //--- data 43 | int Value(void) const { return(m_value); } 44 | void Value(const int value) { m_value=value; } 45 | //--- methods for working with files 46 | virtual bool Save(const int file_handle); 47 | virtual bool Load(const int file_handle); 48 | 49 | protected: 50 | //--- create dependent controls 51 | virtual bool CreateButton(void); 52 | virtual bool CreateLabel(void); 53 | //--- handlers of the dependent controls events 54 | virtual bool OnClickButton(void); 55 | virtual bool OnClickLabel(void); 56 | }; 57 | //+------------------------------------------------------------------+ 58 | //| Common handler of chart events | 59 | //+------------------------------------------------------------------+ 60 | EVENT_MAP_BEGIN(CCheckBox) 61 | ON_EVENT(ON_CLICK,m_button,OnClickButton) 62 | ON_EVENT(ON_CLICK,m_label,OnClickLabel) 63 | EVENT_MAP_END(CWndContainer) 64 | //+------------------------------------------------------------------+ 65 | //| Constructor | 66 | //+------------------------------------------------------------------+ 67 | CCheckBox::CCheckBox(void) : m_value(0) 68 | { 69 | } 70 | //+------------------------------------------------------------------+ 71 | //| Destructor | 72 | //+------------------------------------------------------------------+ 73 | CCheckBox::~CCheckBox(void) 74 | { 75 | } 76 | //+------------------------------------------------------------------+ 77 | //| Create a control | 78 | //+------------------------------------------------------------------+ 79 | bool CCheckBox::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 80 | { 81 | //--- call method of the parent class 82 | if(!CWndContainer::Create(chart,name,subwin,x1,y1,x2,y2)) 83 | return(false); 84 | //--- create dependent controls 85 | if(!CreateButton()) 86 | return(false); 87 | if(!CreateLabel()) 88 | return(false); 89 | //--- succeeded 90 | return(true); 91 | } 92 | //+------------------------------------------------------------------+ 93 | //| Create button | 94 | //+------------------------------------------------------------------+ 95 | bool CCheckBox::CreateButton(void) 96 | { 97 | //--- calculate coordinates 98 | int x1=CONTROLS_CHECK_BUTTON_X_OFF; 99 | int y1=CONTROLS_CHECK_BUTTON_Y_OFF; 100 | int x2=x1+CONTROLS_BUTTON_SIZE; 101 | int y2=y1+CONTROLS_BUTTON_SIZE-CONTROLS_BORDER_WIDTH; 102 | //--- create 103 | if(!m_button.Create(m_chart_id,m_name+"Button",m_subwin,x1,y1,x2,y2)) 104 | return(false); 105 | if(!m_button.BmpNames("::res\\CheckBoxOff.bmp","::res\\CheckBoxOn.bmp")) 106 | return(false); 107 | if(!Add(m_button)) 108 | return(false); 109 | m_button.Locking(true); 110 | //--- succeeded 111 | return(true); 112 | } 113 | //+------------------------------------------------------------------+ 114 | //| Create label | 115 | //+------------------------------------------------------------------+ 116 | bool CCheckBox::CreateLabel(void) 117 | { 118 | //--- calculate coordinates 119 | int x1=CONTROLS_CHECK_LABEL_X_OFF; 120 | int y1=CONTROLS_CHECK_LABEL_Y_OFF; 121 | int x2=Width(); 122 | int y2=Height(); 123 | //--- create 124 | if(!m_label.Create(m_chart_id,m_name+"Label",m_subwin,x1,y1,x2,y2)) 125 | return(false); 126 | if(!m_label.Text(m_name)) 127 | return(false); 128 | if(!Add(m_label)) 129 | return(false); 130 | m_label.ReadOnly(true); 131 | m_label.ColorBackground(CONTROLS_CHECKGROUP_COLOR_BG); 132 | m_label.ColorBorder(CONTROLS_CHECKGROUP_COLOR_BG); 133 | //--- succeeded 134 | return(true); 135 | } 136 | //+------------------------------------------------------------------+ 137 | //| | 138 | //+------------------------------------------------------------------+ 139 | bool CCheckBox::Save(const int file_handle) 140 | { 141 | //--- check 142 | if(file_handle==INVALID_HANDLE) 143 | return(false); 144 | //--- 145 | FileWriteInteger(file_handle,Checked()); 146 | //--- succeed 147 | return(true); 148 | } 149 | //+------------------------------------------------------------------+ 150 | //| | 151 | //+------------------------------------------------------------------+ 152 | bool CCheckBox::Load(const int file_handle) 153 | { 154 | //--- check 155 | if(file_handle==INVALID_HANDLE) 156 | return(false); 157 | //--- 158 | if(!FileIsEnding(file_handle)) 159 | Checked(FileReadInteger(file_handle)); 160 | //--- succeed 161 | return(true); 162 | } 163 | //+------------------------------------------------------------------+ 164 | //| Handler of click on button | 165 | //+------------------------------------------------------------------+ 166 | bool CCheckBox::OnClickButton(void) 167 | { 168 | //--- send the "changed state" event 169 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_CHANGE,m_id,0.0,m_name); 170 | //--- handled 171 | return(true); 172 | } 173 | //+------------------------------------------------------------------+ 174 | //| Handler of click on label | 175 | //+------------------------------------------------------------------+ 176 | bool CCheckBox::OnClickLabel(void) 177 | { 178 | //--- change button state 179 | m_button.Pressed(!m_button.Pressed()); 180 | //--- return the result of the button click handler 181 | return(OnClickButton()); 182 | } 183 | //+------------------------------------------------------------------+ 184 | -------------------------------------------------------------------------------- /Include/ChartObjects/ChartObjectPanel.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| ChartObjectPanel.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include 7 | #include 8 | #include 9 | //+------------------------------------------------------------------+ 10 | //| Class CChartObjectPanel. | 11 | //| Purpose: Class for grouping objects for managing a chart | 12 | //+------------------------------------------------------------------+ 13 | class CChartObjectPanel : public CChartObjectButton 14 | { 15 | protected: 16 | CArrayObj m_attachment; // array of attached objects 17 | CArrayInt m_dX; // array of dX attached objects 18 | CArrayInt m_dY; // array of dY attached objects 19 | bool m_expanded; // collapsed/expanded flag 20 | 21 | public: 22 | CChartObjectPanel(); 23 | ~CChartObjectPanel(); 24 | //--- method for attaching objects 25 | bool Attach(CChartObjectLabel *chart_object); 26 | bool X_Distance(const int X); 27 | bool Y_Distance(const int Y); 28 | int X_Size() const; 29 | int Y_Size() const; 30 | virtual bool Timeframes(const int timeframes); 31 | bool State(const bool state); 32 | bool CheckState(); 33 | 34 | protected: 35 | }; 36 | //+------------------------------------------------------------------+ 37 | //| Constructor | 38 | //+------------------------------------------------------------------+ 39 | void CChartObjectPanel::CChartObjectPanel(void) : m_expanded(true) 40 | { 41 | } 42 | //+------------------------------------------------------------------+ 43 | //| Destructor. | 44 | //+------------------------------------------------------------------+ 45 | void CChartObjectPanel::~CChartObjectPanel(void) 46 | { 47 | //--- All objects added by the method Add(), deleted automatically 48 | } 49 | //+------------------------------------------------------------------+ 50 | //| Method Attach | 51 | //+------------------------------------------------------------------+ 52 | bool CChartObjectPanel::Attach(CChartObjectLabel *chart_object) 53 | { 54 | if(m_attachment.Add(chart_object)) 55 | { 56 | int x,y; 57 | x=chart_object.X_Distance(); 58 | m_dX.Add(chart_object.X_Distance()); 59 | x+=X_Distance(); 60 | chart_object.X_Distance(X_Distance()+chart_object.X_Distance()); 61 | y=CChartObjectButton::Y_Size(); 62 | y+=chart_object.Y_Distance(); 63 | m_dY.Add(chart_object.Y_Distance()+CChartObjectButton::Y_Size()+2); 64 | chart_object.Y_Distance(Y_Distance()+chart_object.Y_Distance()+CChartObjectButton::Y_Size()+2); 65 | return(true); 66 | } 67 | //--- 68 | return(false); 69 | } 70 | //+------------------------------------------------------------------+ 71 | //| Method X_Distance | 72 | //+------------------------------------------------------------------+ 73 | bool CChartObjectPanel::X_Distance(const int X) 74 | { 75 | CChartObjectLabel *chart_object; 76 | //--- 77 | for(int i=0;i 8 | //+------------------------------------------------------------------+ 9 | //| Class CEdit | 10 | //| Usage: control that is displayed by | 11 | //| the CChartObjectEdit object | 12 | //+------------------------------------------------------------------+ 13 | class CEdit : public CWndObj 14 | { 15 | private: 16 | CChartObjectEdit m_edit; // chart object 17 | //--- parameters of the chart object 18 | bool m_read_only; // "read-only" mode flag 19 | ENUM_ALIGN_MODE m_align_mode; // align mode 20 | 21 | public: 22 | CEdit(void); 23 | ~CEdit(void); 24 | //--- create 25 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 26 | //--- chart event handler 27 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 28 | //--- parameters of the chart object 29 | bool ReadOnly(void) const { return(m_read_only); } 30 | bool ReadOnly(const bool flag); 31 | ENUM_ALIGN_MODE TextAlign(void) const { return(m_align_mode); } 32 | bool TextAlign(const ENUM_ALIGN_MODE align); 33 | //--- data access 34 | string Text(void) const { return(m_edit.Description()); } 35 | 36 | protected: 37 | //--- handlers of object events 38 | virtual bool OnObjectEndEdit(void); 39 | //--- handlers of object settings 40 | virtual bool OnSetText(void) { return(m_edit.Description(m_text)); } 41 | virtual bool OnSetColor(void) { return(m_edit.Color(m_color)); } 42 | virtual bool OnSetColorBackground(void) { return(m_edit.BackColor(m_color_background)); } 43 | virtual bool OnSetColorBorder(void) { return(m_edit.BorderColor(m_color_border)); } 44 | virtual bool OnSetFont(void) { return(m_edit.Font(m_font)); } 45 | virtual bool OnSetFontSize(void) { return(m_edit.FontSize(m_font_size)); } 46 | virtual bool OnSetZOrder(void) { return(m_edit.Z_Order(m_zorder)); } 47 | //--- internal event handlers 48 | virtual bool OnCreate(void); 49 | virtual bool OnShow(void); 50 | virtual bool OnHide(void); 51 | virtual bool OnMove(void); 52 | virtual bool OnResize(void); 53 | virtual bool OnChange(void); 54 | virtual bool OnClick(void); 55 | }; 56 | //+------------------------------------------------------------------+ 57 | //| Common handler of chart events | 58 | //+------------------------------------------------------------------+ 59 | bool CEdit::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam) 60 | { 61 | if(m_name==sparam && id==CHARTEVENT_OBJECT_ENDEDIT) 62 | return(OnObjectEndEdit()); 63 | //--- event was not handled 64 | return(CWndObj::OnEvent(id,lparam,dparam,sparam)); 65 | } 66 | //+------------------------------------------------------------------+ 67 | //| Constructor | 68 | //+------------------------------------------------------------------+ 69 | CEdit::CEdit(void) : m_read_only(false), 70 | m_align_mode(ALIGN_LEFT) 71 | { 72 | m_color =CONTROLS_EDIT_COLOR; 73 | m_color_background=CONTROLS_EDIT_COLOR_BG; 74 | m_color_border =CONTROLS_EDIT_COLOR_BORDER; 75 | } 76 | //+------------------------------------------------------------------+ 77 | //| Destructor | 78 | //+------------------------------------------------------------------+ 79 | CEdit::~CEdit(void) 80 | { 81 | } 82 | //+------------------------------------------------------------------+ 83 | //| Create a control | 84 | //+------------------------------------------------------------------+ 85 | bool CEdit::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 86 | { 87 | //--- call method of the parent class 88 | if(!CWndObj::Create(chart,name,subwin,x1,y1,x2,y2)) 89 | return(false); 90 | //--- create the chart object 91 | if(!m_edit.Create(chart,name,subwin,x1,y1,Width(),Height())) 92 | return(false); 93 | //--- call the settings handler 94 | return(OnChange()); 95 | } 96 | //+------------------------------------------------------------------+ 97 | //| Set parameter | 98 | //+------------------------------------------------------------------+ 99 | bool CEdit::ReadOnly(const bool flag) 100 | { 101 | //--- save new value of parameter 102 | m_read_only=flag; 103 | //--- set up the chart object 104 | return(m_edit.ReadOnly(flag)); 105 | } 106 | //+------------------------------------------------------------------+ 107 | //| Set parameter | 108 | //+------------------------------------------------------------------+ 109 | bool CEdit::TextAlign(const ENUM_ALIGN_MODE align) 110 | { 111 | //--- save new value of parameter 112 | m_align_mode=align; 113 | //--- set up the chart object 114 | return(m_edit.TextAlign(align)); 115 | } 116 | //+------------------------------------------------------------------+ 117 | //| Create object on chart | 118 | //+------------------------------------------------------------------+ 119 | bool CEdit::OnCreate(void) 120 | { 121 | //--- create the chart object by previously set parameters 122 | return(m_edit.Create(m_chart_id,m_name,m_subwin,m_rect.left,m_rect.top,m_rect.Width(),m_rect.Height())); 123 | } 124 | //+------------------------------------------------------------------+ 125 | //| Display object on chart | 126 | //+------------------------------------------------------------------+ 127 | bool CEdit::OnShow(void) 128 | { 129 | return(m_edit.Timeframes(OBJ_ALL_PERIODS)); 130 | } 131 | //+------------------------------------------------------------------+ 132 | //| Hide object from chart | 133 | //+------------------------------------------------------------------+ 134 | bool CEdit::OnHide(void) 135 | { 136 | return(m_edit.Timeframes(OBJ_NO_PERIODS)); 137 | } 138 | //+------------------------------------------------------------------+ 139 | //| Absolute movement of the chart object | 140 | //+------------------------------------------------------------------+ 141 | bool CEdit::OnMove(void) 142 | { 143 | //--- position the chart object 144 | return(m_edit.X_Distance(m_rect.left) && m_edit.Y_Distance(m_rect.top)); 145 | } 146 | //+------------------------------------------------------------------+ 147 | //| Resize the chart object | 148 | //+------------------------------------------------------------------+ 149 | bool CEdit::OnResize(void) 150 | { 151 | //--- resize the chart object 152 | return(m_edit.X_Size(m_rect.Width()) && m_edit.Y_Size(m_rect.Height())); 153 | } 154 | //+------------------------------------------------------------------+ 155 | //| Set up the chart object | 156 | //+------------------------------------------------------------------+ 157 | bool CEdit::OnChange(void) 158 | { 159 | //--- set up the chart object 160 | return(CWndObj::OnChange() && ReadOnly(m_read_only) && TextAlign(m_align_mode)); 161 | } 162 | //+------------------------------------------------------------------+ 163 | //| Handler of the "End of editing" event | 164 | //+------------------------------------------------------------------+ 165 | bool CEdit::OnObjectEndEdit(void) 166 | { 167 | //--- send the ON_END_EDIT notification 168 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_END_EDIT,m_id,0.0,m_name); 169 | //--- handled 170 | return(true); 171 | } 172 | //+------------------------------------------------------------------+ 173 | //| Handler of the "click" event | 174 | //+------------------------------------------------------------------+ 175 | bool CEdit::OnClick(void) 176 | { 177 | //--- if editing is enabled, send the ON_START_EDIT notification 178 | if(!m_read_only) 179 | { 180 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_START_EDIT,m_id,0.0,m_name); 181 | //--- handled 182 | return(true); 183 | } 184 | //--- else send the ON_CLICK notification 185 | return(CWnd::OnClick()); 186 | } 187 | //+------------------------------------------------------------------+ 188 | -------------------------------------------------------------------------------- /Include/ChartObjects/ChartObjectsElliott.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| ChartObjectsElliott.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | //| All Elliott tools. | 7 | //+------------------------------------------------------------------+ 8 | #include "ChartObject.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Class CChartObjectElliottWave3. | 11 | //| Purpose: Class of the "ElliottCorrectiveWave" object of chart. | 12 | //| Derives from class CChartObject. | 13 | //+------------------------------------------------------------------+ 14 | class CChartObjectElliottWave3 : public CChartObject 15 | { 16 | public: 17 | CChartObjectElliottWave3(void); 18 | ~CChartObjectElliottWave3(void); 19 | //--- methods of access to properties of the object 20 | ENUM_ELLIOT_WAVE_DEGREE Degree(void) const; 21 | bool Degree(const ENUM_ELLIOT_WAVE_DEGREE degree) const; 22 | bool Lines(void) const; 23 | bool Lines(const bool lines) const; 24 | //--- method of creating the object 25 | bool Create(long chart_id,const string name,const int window, 26 | const datetime time1,const double price1, 27 | const datetime time2,const double price2, 28 | const datetime time3,const double price3); 29 | //--- method of identifying the object 30 | virtual int Type(void) const { return(OBJ_ELLIOTWAVE3); } 31 | //--- methods for working with files 32 | virtual bool Save(const int file_handle); 33 | virtual bool Load(const int file_handle); 34 | }; 35 | //+------------------------------------------------------------------+ 36 | //| Constructor | 37 | //+------------------------------------------------------------------+ 38 | CChartObjectElliottWave3::CChartObjectElliottWave3(void) 39 | { 40 | } 41 | //+------------------------------------------------------------------+ 42 | //| Destructor | 43 | //+------------------------------------------------------------------+ 44 | CChartObjectElliottWave3::~CChartObjectElliottWave3(void) 45 | { 46 | } 47 | //+------------------------------------------------------------------+ 48 | //| Create object "ElliottCorrectiveWave" | 49 | //+------------------------------------------------------------------+ 50 | bool CChartObjectElliottWave3::Create(long chart_id,const string name,const int window, 51 | const datetime time1,const double price1, 52 | const datetime time2,const double price2, 53 | const datetime time3,const double price3) 54 | { 55 | if(!ObjectCreate(chart_id,name,OBJ_ELLIOTWAVE3,window,time1,price1,time2,price2,time3,price3)) 56 | return(false); 57 | if(!Attach(chart_id,name,window,3)) 58 | return(false); 59 | //--- successful 60 | return(true); 61 | } 62 | //+------------------------------------------------------------------+ 63 | //| Get value of the "Degree" property | 64 | //+------------------------------------------------------------------+ 65 | ENUM_ELLIOT_WAVE_DEGREE CChartObjectElliottWave3::Degree(void) const 66 | { 67 | //--- check 68 | if(m_chart_id==-1) 69 | return(WRONG_VALUE); 70 | //--- result 71 | return((ENUM_ELLIOT_WAVE_DEGREE)ObjectGetInteger(m_chart_id,m_name,OBJPROP_DEGREE)); 72 | } 73 | //+------------------------------------------------------------------+ 74 | //| Set value for the "Degree" property | 75 | //+------------------------------------------------------------------+ 76 | bool CChartObjectElliottWave3::Degree(const ENUM_ELLIOT_WAVE_DEGREE degree) const 77 | { 78 | //--- check 79 | if(m_chart_id==-1) 80 | return(false); 81 | //--- result 82 | return(ObjectSetInteger(m_chart_id,m_name,OBJPROP_DEGREE,degree)); 83 | } 84 | //+------------------------------------------------------------------+ 85 | //| Get value of the "Lines" property | 86 | //+------------------------------------------------------------------+ 87 | bool CChartObjectElliottWave3::Lines(void) const 88 | { 89 | //--- check 90 | if(m_chart_id==-1) 91 | return(false); 92 | //--- result 93 | return((bool)ObjectGetInteger(m_chart_id,m_name,OBJPROP_DRAWLINES)); 94 | } 95 | //+------------------------------------------------------------------+ 96 | //| Set value for the "Lines" property | 97 | //+------------------------------------------------------------------+ 98 | bool CChartObjectElliottWave3::Lines(const bool lines) const 99 | { 100 | //--- check 101 | if(m_chart_id==-1) 102 | return(false); 103 | //--- result 104 | return(ObjectSetInteger(m_chart_id,m_name,OBJPROP_DRAWLINES,lines)); 105 | } 106 | //+------------------------------------------------------------------+ 107 | //| Writing parameters of object to file | 108 | //+------------------------------------------------------------------+ 109 | bool CChartObjectElliottWave3::Save(const int file_handle) 110 | { 111 | bool result; 112 | //--- check 113 | if(file_handle==INVALID_HANDLE || m_chart_id==-1) 114 | return(false); 115 | //--- write 116 | result=CChartObject::Save(file_handle); 117 | if(result) 118 | { 119 | //--- write value of the "Degree" property 120 | if(FileWriteInteger(file_handle,(int)ObjectGetInteger(m_chart_id,m_name,OBJPROP_DEGREE),INT_VALUE)!=sizeof(int)) 121 | return(false); 122 | //--- write value of the "Lines" property 123 | if(FileWriteInteger(file_handle,(int)ObjectGetInteger(m_chart_id,m_name,OBJPROP_DRAWLINES),INT_VALUE)!=sizeof(int)) 124 | return(false); 125 | } 126 | //--- result 127 | return(result); 128 | } 129 | //+------------------------------------------------------------------+ 130 | //| Reading parameters of object from file | 131 | //+------------------------------------------------------------------+ 132 | bool CChartObjectElliottWave3::Load(const int file_handle) 133 | { 134 | bool result; 135 | //--- check 136 | if(file_handle==INVALID_HANDLE || m_chart_id==-1) 137 | return(false); 138 | //--- read 139 | result=CChartObject::Load(file_handle); 140 | if(result) 141 | { 142 | //--- read value of the "Degree" property 143 | if(!ObjectSetInteger(m_chart_id,m_name,OBJPROP_DEGREE,FileReadInteger(file_handle,INT_VALUE))) 144 | return(false); 145 | //--- read value of the "Lines" property 146 | if(!ObjectSetInteger(m_chart_id,m_name,OBJPROP_DRAWLINES,FileReadInteger(file_handle,INT_VALUE))) 147 | return(false); 148 | } 149 | //--- result 150 | return(result); 151 | } 152 | //+------------------------------------------------------------------+ 153 | //| Class CChartObjectElliottWave5. | 154 | //| Purpose: Class of the "ElliottMotiveWave" object of chart. | 155 | //| Derives from class CChartObjectElliottWave3. | 156 | //+------------------------------------------------------------------+ 157 | class CChartObjectElliottWave5 : public CChartObjectElliottWave3 158 | { 159 | public: 160 | CChartObjectElliottWave5(void); 161 | ~CChartObjectElliottWave5(void); 162 | //--- method of creating the object 163 | bool Create(long chart_id,const string name,const int window, 164 | const datetime time1,const double price1, 165 | const datetime time2,const double price2, 166 | const datetime time3,const double price3, 167 | const datetime time4,const double price4, 168 | const datetime time5,const double price5); 169 | //--- method of identifying the object 170 | virtual int Type(void) const { return(OBJ_ELLIOTWAVE5); } 171 | }; 172 | //+------------------------------------------------------------------+ 173 | //| Constructor | 174 | //+------------------------------------------------------------------+ 175 | CChartObjectElliottWave5::CChartObjectElliottWave5(void) 176 | { 177 | } 178 | //+------------------------------------------------------------------+ 179 | //| Destructor | 180 | //+------------------------------------------------------------------+ 181 | CChartObjectElliottWave5::~CChartObjectElliottWave5(void) 182 | { 183 | } 184 | //+------------------------------------------------------------------+ 185 | //| Create object "ElliottMotiveWave" | 186 | //+------------------------------------------------------------------+ 187 | bool CChartObjectElliottWave5::Create(long chart_id,const string name,const int window, 188 | const datetime time1,const double price1, 189 | const datetime time2,const double price2, 190 | const datetime time3,const double price3, 191 | const datetime time4,const double price4, 192 | const datetime time5,const double price5) 193 | { 194 | if(!ObjectCreate(chart_id,name,OBJ_ELLIOTWAVE5,window,time1,price1,time2,price2,time3,price3,time4,price4,time5,price5)) 195 | return(false); 196 | if(!Attach(chart_id,name,window,5)) 197 | return(false); 198 | //--- successful 199 | return(true); 200 | } 201 | //+------------------------------------------------------------------+ 202 | -------------------------------------------------------------------------------- /Include/Controls/SpinEdit.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| SpinEdit.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndContainer.mqh" 7 | #include "Edit.mqh" 8 | #include "BmpButton.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Resources | 11 | //+------------------------------------------------------------------+ 12 | #resource "res\\SpinInc.bmp" 13 | #resource "res\\SpinDec.bmp" 14 | //+------------------------------------------------------------------+ 15 | //| Class CSpinEdit | 16 | //| Usage: class that implements the "Up-Down" control | 17 | //+------------------------------------------------------------------+ 18 | class CSpinEdit : public CWndContainer 19 | { 20 | private: 21 | //--- dependent controls 22 | CEdit m_edit; // the entry field object 23 | CBmpButton m_inc; // the "Increment button" object 24 | CBmpButton m_dec; // the "Decrement button" object 25 | //--- adjusted parameters 26 | int m_min_value; // minimum value 27 | int m_max_value; // maximum value 28 | //--- state 29 | int m_value; // current value 30 | 31 | public: 32 | CSpinEdit(void); 33 | ~CSpinEdit(void); 34 | //--- create 35 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 36 | //--- chart event handler 37 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 38 | //--- set up 39 | int MinValue(void) const { return(m_min_value); } 40 | void MinValue(const int value); 41 | int MaxValue(void) const { return(m_min_value); } 42 | void MaxValue(const int value); 43 | //--- state 44 | int Value(void) const { return(m_value); } 45 | bool Value(int value); 46 | //--- methods for working with files 47 | virtual bool Save(const int file_handle); 48 | virtual bool Load(const int file_handle); 49 | 50 | protected: 51 | //--- create dependent controls 52 | virtual bool CreateEdit(void); 53 | virtual bool CreateInc(void); 54 | virtual bool CreateDec(void); 55 | //--- handlers of the dependent controls events 56 | virtual bool OnClickInc(void); 57 | virtual bool OnClickDec(void); 58 | //--- internal event handlers 59 | virtual bool OnChangeValue(void); 60 | }; 61 | //+------------------------------------------------------------------+ 62 | //| Common handler of chart events | 63 | //+------------------------------------------------------------------+ 64 | EVENT_MAP_BEGIN(CSpinEdit) 65 | ON_EVENT(ON_CLICK,m_inc,OnClickInc) 66 | ON_EVENT(ON_CLICK,m_dec,OnClickDec) 67 | EVENT_MAP_END(CWndContainer) 68 | //+------------------------------------------------------------------+ 69 | //| Constructor | 70 | //+------------------------------------------------------------------+ 71 | CSpinEdit::CSpinEdit(void) : m_min_value(0), 72 | m_max_value(0), 73 | m_value(0) 74 | { 75 | } 76 | //+------------------------------------------------------------------+ 77 | //| Destructor | 78 | //+------------------------------------------------------------------+ 79 | CSpinEdit::~CSpinEdit(void) 80 | { 81 | } 82 | //+------------------------------------------------------------------+ 83 | //| Create a control | 84 | //+------------------------------------------------------------------+ 85 | bool CSpinEdit::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 86 | { 87 | //--- check height 88 | if(y2-y1m_max_value) 112 | value=m_max_value; 113 | //--- if value was changed 114 | if(m_value!=value) 115 | { 116 | m_value=value; 117 | //--- call virtual handler 118 | return(OnChangeValue()); 119 | } 120 | //--- value has not been changed 121 | return(false); 122 | } 123 | //+------------------------------------------------------------------+ 124 | //| | 125 | //+------------------------------------------------------------------+ 126 | bool CSpinEdit::Save(const int file_handle) 127 | { 128 | //--- check 129 | if(file_handle==INVALID_HANDLE) 130 | return(false); 131 | //--- 132 | FileWriteInteger(file_handle,m_value); 133 | //--- succeed 134 | return(true); 135 | } 136 | //+------------------------------------------------------------------+ 137 | //| | 138 | //+------------------------------------------------------------------+ 139 | bool CSpinEdit::Load(const int file_handle) 140 | { 141 | //--- check 142 | if(file_handle==INVALID_HANDLE) 143 | return(false); 144 | //--- 145 | if(!FileIsEnding(file_handle)) 146 | Value(FileReadInteger(file_handle)); 147 | //--- succeed 148 | return(true); 149 | } 150 | //+------------------------------------------------------------------+ 151 | //| Set minimum value | 152 | //+------------------------------------------------------------------+ 153 | void CSpinEdit::MinValue(const int value) 154 | { 155 | //--- if value was changed 156 | if(m_min_value!=value) 157 | { 158 | m_min_value=value; 159 | //--- adjust the edit value 160 | Value(m_value); 161 | } 162 | } 163 | //+------------------------------------------------------------------+ 164 | //| Set maximum value | 165 | //+------------------------------------------------------------------+ 166 | void CSpinEdit::MaxValue(const int value) 167 | { 168 | //--- if value was changed 169 | if(m_max_value!=value) 170 | { 171 | m_max_value=value; 172 | //--- adjust the edit value 173 | Value(m_value); 174 | } 175 | } 176 | //+------------------------------------------------------------------+ 177 | //| Create the edit field | 178 | //+------------------------------------------------------------------+ 179 | bool CSpinEdit::CreateEdit(void) 180 | { 181 | //--- create 182 | if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,0,0,Width(),Height())) 183 | return(false); 184 | if(!m_edit.Text("")) 185 | return(false); 186 | if(!m_edit.ReadOnly(true)) 187 | return(false); 188 | if(!Add(m_edit)) 189 | return(false); 190 | //--- succeed 191 | return(true); 192 | } 193 | //+------------------------------------------------------------------+ 194 | //| Create the "Increment" button | 195 | //+------------------------------------------------------------------+ 196 | bool CSpinEdit::CreateInc(void) 197 | { 198 | //--- right align button (try to make equal offsets from top and bottom) 199 | int x1=Width()-(CONTROLS_BUTTON_SIZE+CONTROLS_SPIN_BUTTON_X_OFF); 200 | int y1=(Height()-2*CONTROLS_SPIN_BUTTON_SIZE)/2; 201 | int x2=x1+CONTROLS_BUTTON_SIZE; 202 | int y2=y1+CONTROLS_SPIN_BUTTON_SIZE; 203 | //--- create 204 | if(!m_inc.Create(m_chart_id,m_name+"Inc",m_subwin,x1,y1,x2,y2)) 205 | return(false); 206 | if(!m_inc.BmpNames("::res\\SpinInc.bmp")) 207 | return(false); 208 | if(!Add(m_inc)) 209 | return(false); 210 | //--- property 211 | m_inc.PropFlags(WND_PROP_FLAG_CLICKS_BY_PRESS); 212 | //--- succeed 213 | return(true); 214 | } 215 | //+------------------------------------------------------------------+ 216 | //| Create the "Decrement" button | 217 | //+------------------------------------------------------------------+ 218 | bool CSpinEdit::CreateDec(void) 219 | { 220 | //--- right align button (try to make equal offsets from top and bottom) 221 | int x1=Width()-(CONTROLS_BUTTON_SIZE+CONTROLS_SPIN_BUTTON_X_OFF); 222 | int y1=(Height()-2*CONTROLS_SPIN_BUTTON_SIZE)/2+CONTROLS_SPIN_BUTTON_SIZE; 223 | int x2=x1+CONTROLS_BUTTON_SIZE; 224 | int y2=y1+CONTROLS_SPIN_BUTTON_SIZE; 225 | //--- create 226 | if(!m_dec.Create(m_chart_id,m_name+"Dec",m_subwin,x1,y1,x2,y2)) 227 | return(false); 228 | if(!m_dec.BmpNames("::res\\SpinDec.bmp")) 229 | return(false); 230 | if(!Add(m_dec)) 231 | return(false); 232 | //--- property 233 | m_dec.PropFlags(WND_PROP_FLAG_CLICKS_BY_PRESS); 234 | //--- succeed 235 | return(true); 236 | } 237 | //+------------------------------------------------------------------+ 238 | //| Handler of click on the "increment" button | 239 | //+------------------------------------------------------------------+ 240 | bool CSpinEdit::OnClickInc(void) 241 | { 242 | //--- try to increment current value 243 | return(Value(m_value+1)); 244 | } 245 | //+------------------------------------------------------------------+ 246 | //| Handler of click on the "decrement" button | 247 | //+------------------------------------------------------------------+ 248 | bool CSpinEdit::OnClickDec(void) 249 | { 250 | //--- try to decrement current value 251 | return(Value(m_value-1)); 252 | } 253 | //+------------------------------------------------------------------+ 254 | //| Handler of changing current state | 255 | //+------------------------------------------------------------------+ 256 | bool CSpinEdit::OnChangeValue(void) 257 | { 258 | //--- copy text to the edit field edit 259 | m_edit.Text(IntegerToString(m_value)); 260 | //--- send notification 261 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_CHANGE,m_id,0.0,m_name); 262 | //--- handled 263 | return(true); 264 | } 265 | //+------------------------------------------------------------------+ 266 | -------------------------------------------------------------------------------- /Include/Controls/WndObj.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| WndObj.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "Wnd.mqh" 7 | //+------------------------------------------------------------------+ 8 | //| Class CWndObj | 9 | //| Usage: base class to work with chart objects | 10 | //+------------------------------------------------------------------+ 11 | class CWndObj : public CWnd 12 | { 13 | private: 14 | //--- flags of object 15 | bool m_undeletable; // "object is not deletable" flag 16 | bool m_unchangeable; // "object is not changeable" flag 17 | bool m_unmoveable; // "object is not movable" flag 18 | 19 | protected: 20 | //--- parameters of the chart object 21 | string m_text; // object text 22 | color m_color; // object color 23 | color m_color_background; // object background color 24 | color m_color_border; // object border color 25 | string m_font; // object font 26 | int m_font_size; // object font size 27 | long m_zorder; // Z order 28 | 29 | public: 30 | CWndObj(void); 31 | ~CWndObj(void); 32 | //--- chart event handler 33 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 34 | //--- set up the object 35 | string Text(void) const { return(m_text); } 36 | bool Text(const string value); 37 | color Color(void) const { return(m_color); } 38 | bool Color(const color value); 39 | color ColorBackground(void) const { return(m_color_background); } 40 | bool ColorBackground(const color value); 41 | color ColorBorder(void) const { return(m_color_border); } 42 | bool ColorBorder(const color value); 43 | string Font(void) const { return(m_font); } 44 | bool Font(const string value); 45 | int FontSize(void) const { return(m_font_size); } 46 | bool FontSize(const int value); 47 | long ZOrder(void) const { return(m_zorder); } 48 | bool ZOrder(const long value); 49 | 50 | protected: 51 | //--- handlers of object events 52 | virtual bool OnObjectCreate(void); 53 | virtual bool OnObjectChange(void); 54 | virtual bool OnObjectDelete(void); 55 | virtual bool OnObjectDrag(void); 56 | //--- handlers of object settings 57 | virtual bool OnSetText(void) { return(true); } 58 | virtual bool OnSetColor(void) { return(true); } 59 | virtual bool OnSetColorBackground(void) { return(true); } 60 | virtual bool OnSetColorBorder(void) { return(true); } 61 | virtual bool OnSetFont(void) { return(true); } 62 | virtual bool OnSetFontSize(void) { return(true); } 63 | virtual bool OnSetZOrder(void) { return(true); } 64 | //--- internal event handlers 65 | virtual bool OnDestroy(void) { return(ObjectDelete(m_chart_id,m_name)); } 66 | virtual bool OnChange(void); 67 | }; 68 | //+------------------------------------------------------------------+ 69 | //| Common handler of chart events | 70 | //+------------------------------------------------------------------+ 71 | bool CWndObj::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam) 72 | { 73 | if(m_name==sparam) 74 | { 75 | //--- object name and string parameters are equal 76 | //--- this means that event should be handled 77 | switch(id) 78 | { 79 | case CHARTEVENT_OBJECT_CREATE: return(OnObjectCreate()); 80 | case CHARTEVENT_OBJECT_CHANGE: return(OnObjectChange()); 81 | case CHARTEVENT_OBJECT_DELETE: return(OnObjectDelete()); 82 | case CHARTEVENT_OBJECT_DRAG : return(OnObjectDrag()); 83 | } 84 | } 85 | //--- event was not handled 86 | return(CWnd::OnEvent(id,lparam,dparam,sparam)); 87 | } 88 | //+------------------------------------------------------------------+ 89 | //| Constructor | 90 | //+------------------------------------------------------------------+ 91 | CWndObj::CWndObj(void) : m_color(clrNONE), 92 | m_color_background(clrNONE), 93 | m_color_border(clrNONE), 94 | m_font(CONTROLS_FONT_NAME), 95 | m_font_size(CONTROLS_FONT_SIZE), 96 | m_zorder(0), 97 | m_undeletable(true), 98 | m_unchangeable(true), 99 | m_unmoveable(true) 100 | { 101 | } 102 | //+------------------------------------------------------------------+ 103 | //| Destructor | 104 | //+------------------------------------------------------------------+ 105 | CWndObj::~CWndObj(void) 106 | { 107 | } 108 | //+------------------------------------------------------------------+ 109 | //| Set the "Text" parameter | 110 | //+------------------------------------------------------------------+ 111 | bool CWndObj::Text(const string value) 112 | { 113 | //--- save new value of parameter 114 | m_text=value; 115 | //--- call virtual event handler 116 | return(OnSetText()); 117 | } 118 | //+------------------------------------------------------------------+ 119 | //| Set the "Color" parameter | 120 | //+------------------------------------------------------------------+ 121 | bool CWndObj::Color(const color value) 122 | { 123 | //--- save new value of parameter 124 | m_color=value; 125 | //--- call virtual event handler 126 | return(OnSetColor()); 127 | } 128 | //+------------------------------------------------------------------+ 129 | //| Setting the "Background color" parameter | 130 | //+------------------------------------------------------------------+ 131 | bool CWndObj::ColorBackground(const color value) 132 | { 133 | //--- save new value of parameter 134 | m_color_background=value; 135 | //--- call virtual event handler 136 | return(OnSetColorBackground()); 137 | } 138 | //+------------------------------------------------------------------+ 139 | //| Set the "Border color" parameter | 140 | //+------------------------------------------------------------------+ 141 | bool CWndObj::ColorBorder(const color value) 142 | { 143 | //--- save new value of parameter 144 | m_color_border=value; 145 | //--- call virtual event handler 146 | return(OnSetColorBorder()); 147 | } 148 | //+------------------------------------------------------------------+ 149 | //| Set the "Font" parameter | 150 | //+------------------------------------------------------------------+ 151 | bool CWndObj::Font(const string value) 152 | { 153 | //--- save new value of parameter 154 | m_font=value; 155 | //--- call virtual event handler 156 | return(OnSetFont()); 157 | } 158 | //+------------------------------------------------------------------+ 159 | //| Set the "Font size" parameter | 160 | //+------------------------------------------------------------------+ 161 | bool CWndObj::FontSize(const int value) 162 | { 163 | //--- save new value of parameter 164 | m_font_size=value; 165 | //--- call virtual event handler 166 | return(OnSetFontSize()); 167 | } 168 | //+------------------------------------------------------------------+ 169 | //| Set the "Z order" parameter | 170 | //+------------------------------------------------------------------+ 171 | bool CWndObj::ZOrder(const long value) 172 | { 173 | //--- save new value of parameter 174 | m_zorder=value; 175 | //--- call virtual event handler 176 | return(OnSetZOrder()); 177 | } 178 | //+------------------------------------------------------------------+ 179 | //| Handler of the "Object creation" event | 180 | //+------------------------------------------------------------------+ 181 | bool CWndObj::OnObjectCreate(void) 182 | { 183 | //--- event is handled 184 | return(true); 185 | } 186 | //+------------------------------------------------------------------+ 187 | //| Handler of the "Object modification" event | 188 | //+------------------------------------------------------------------+ 189 | bool CWndObj::OnObjectChange(void) 190 | { 191 | //--- if object is not changeable 192 | if(m_unchangeable) 193 | { 194 | //--- restore position 195 | if(!OnMove()) 196 | return(false); 197 | //--- restore size 198 | if(!OnResize()) 199 | return(false); 200 | //--- restore settings 201 | if(!OnChange()) 202 | return(false); 203 | } 204 | //--- event is handled 205 | return(true); 206 | } 207 | //+------------------------------------------------------------------+ 208 | //| Handler of the "Object deletion" event | 209 | //+------------------------------------------------------------------+ 210 | bool CWndObj::OnObjectDelete(void) 211 | { 212 | //--- if object is not deletable 213 | if(m_undeletable) 214 | { 215 | //--- restore the object 216 | if(!OnCreate()) 217 | return(false); 218 | //--- restore settings 219 | if(!OnChange()) 220 | return(false); 221 | //--- restore visibility 222 | return(IS_VISIBLE ? OnShow():OnHide()); 223 | } 224 | //--- event is handled 225 | return(true); 226 | } 227 | //+------------------------------------------------------------------+ 228 | //| Handler of the "Object dragging" event | 229 | //+------------------------------------------------------------------+ 230 | bool CWndObj::OnObjectDrag(void) 231 | { 232 | //--- if object is not movable 233 | if(m_unmoveable) 234 | { 235 | //--- restore position 236 | return(OnMove()); 237 | } 238 | //--- event is handled 239 | return(true); 240 | } 241 | //+------------------------------------------------------------------+ 242 | //| Set up the object | 243 | //+------------------------------------------------------------------+ 244 | bool CWndObj::OnChange(void) 245 | { 246 | //--- set up the chart object according to previously set parameters 247 | if(!OnSetText()) 248 | return(false); 249 | if(!OnSetFont()) 250 | return(false); 251 | if(!OnSetFontSize()) 252 | return(false); 253 | if(!OnSetColor()) 254 | return(false); 255 | if(!OnSetColorBackground()) 256 | return(false); 257 | if(!OnSetColorBorder()) 258 | return(false); 259 | //--- succeed 260 | return(true); 261 | } 262 | //+------------------------------------------------------------------+ 263 | -------------------------------------------------------------------------------- /Include/Controls/DatePicker.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| DatePicker.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "WndContainer.mqh" 7 | #include "Edit.mqh" 8 | #include "BmpButton.mqh" 9 | #include "DateDropList.mqh" 10 | //+------------------------------------------------------------------+ 11 | //| Resources | 12 | //+------------------------------------------------------------------+ 13 | //--- Can not place the same file into resource twice 14 | #resource "res\\DateDropOn.bmp" // image file 15 | #resource "res\\DateDropOff.bmp" // image file 16 | //+------------------------------------------------------------------+ 17 | //| Class CDatePicker | 18 | //| Usage: date picker | 19 | //+------------------------------------------------------------------+ 20 | class CDatePicker : public CWndContainer 21 | { 22 | private: 23 | //--- dependent controls 24 | CEdit m_edit; // the entry field object 25 | CBmpButton m_drop; // the button object 26 | CDateDropList m_list; // the drop-down list object 27 | //--- data 28 | datetime m_value; // current value 29 | 30 | public: 31 | CDatePicker(void); 32 | ~CDatePicker(void); 33 | //--- create 34 | virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); 35 | //--- chart event handler 36 | virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 37 | //--- data 38 | datetime Value(void) const { return(m_value); } 39 | void Value(datetime value) { m_edit.Text(TimeToString(m_value=value,TIME_DATE)); } 40 | //--- state 41 | virtual bool Show(void); 42 | //--- methods for working with files 43 | virtual bool Save(const int file_handle); 44 | virtual bool Load(const int file_handle); 45 | 46 | protected: 47 | //--- create dependent controls 48 | virtual bool CreateEdit(void); 49 | virtual bool CreateButton(void); 50 | virtual bool CreateList(void); 51 | //--- handlers of the dependent controls events 52 | virtual bool OnClickEdit(void); 53 | virtual bool OnClickButton(void); 54 | virtual bool OnChangeList(void); 55 | //--- show drop-down list 56 | bool ListShow(void); 57 | bool ListHide(void); 58 | void CheckListHide(const int id,int x,int y); 59 | }; 60 | //+------------------------------------------------------------------+ 61 | //| Common handler of chart events | 62 | //+------------------------------------------------------------------+ 63 | EVENT_MAP_BEGIN(CDatePicker) 64 | ON_EVENT(ON_CLICK,m_edit,OnClickEdit) 65 | ON_EVENT(ON_CLICK,m_drop,OnClickButton) 66 | ON_EVENT(ON_CHANGE,m_list,OnChangeList) 67 | CheckListHide(id,(int)lparam,(int)dparam); 68 | //+------------------------------------------------------------------+ 69 | //| | 70 | //+------------------------------------------------------------------+ 71 | EVENT_MAP_END(CWndContainer) 72 | //+------------------------------------------------------------------+ 73 | //| Constructor | 74 | //+------------------------------------------------------------------+ 75 | CDatePicker::CDatePicker(void) : m_value(0) 76 | { 77 | } 78 | //+------------------------------------------------------------------+ 79 | //| Destructor | 80 | //+------------------------------------------------------------------+ 81 | CDatePicker::~CDatePicker(void) 82 | { 83 | } 84 | //+------------------------------------------------------------------+ 85 | //| Create a control | 86 | //+------------------------------------------------------------------+ 87 | bool CDatePicker::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) 88 | { 89 | //--- call method of the parent class 90 | if(!CWndContainer::Create(chart,name,subwin,x1,y1,x2,y2)) 91 | return(false); 92 | //--- create dependent controls 93 | if(!CreateEdit()) 94 | return(false); 95 | if(!CreateButton()) 96 | return(false); 97 | if(!CreateList()) 98 | return(false); 99 | //--- succeeded 100 | return(true); 101 | } 102 | //+------------------------------------------------------------------+ 103 | //| Create main entry field | 104 | //+------------------------------------------------------------------+ 105 | bool CDatePicker::CreateEdit(void) 106 | { 107 | //--- create 108 | if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,0,0,Width(),Height())) 109 | return(false); 110 | if(!m_edit.Text("")) 111 | return(false); 112 | if(!m_edit.ReadOnly(true)) 113 | return(false); 114 | if(!Add(m_edit)) 115 | return(false); 116 | //--- succeeded 117 | return(true); 118 | } 119 | //+------------------------------------------------------------------+ 120 | //| Create button | 121 | //+------------------------------------------------------------------+ 122 | bool CDatePicker::CreateButton(void) 123 | { 124 | //--- right align button (try to make equal offsets from top and bottom) 125 | int x1=Width()-(2*CONTROLS_BUTTON_SIZE+CONTROLS_COMBO_BUTTON_X_OFF); 126 | int y1=(Height()-CONTROLS_BUTTON_SIZE)/2; 127 | int x2=x1+2*CONTROLS_BUTTON_SIZE; 128 | int y2=y1+CONTROLS_BUTTON_SIZE; 129 | //--- create 130 | if(!m_drop.Create(m_chart_id,m_name+"Drop",m_subwin,x1,y1,x2,y2)) 131 | return(false); 132 | if(!m_drop.BmpNames("::res\\DateDropOff.bmp","::res\\DateDropOn.bmp")) 133 | return(false); 134 | if(!Add(m_drop)) 135 | return(false); 136 | m_drop.Locking(true); 137 | //--- succeeded 138 | return(true); 139 | } 140 | //+------------------------------------------------------------------+ 141 | //| Create drop-down list | 142 | //+------------------------------------------------------------------+ 143 | bool CDatePicker::CreateList(void) 144 | { 145 | //--- create 146 | if(!m_list.Create(m_chart_id,m_name+"List",m_subwin,0,Height()-1,Width(),0)) 147 | return(false); 148 | if(!Add(m_list)) 149 | return(false); 150 | m_list.Hide(); 151 | //--- succeeded 152 | return(true); 153 | } 154 | //+------------------------------------------------------------------+ 155 | //| Makes the control visible | 156 | //+------------------------------------------------------------------+ 157 | bool CDatePicker::Show(void) 158 | { 159 | m_edit.Show(); 160 | m_drop.Show(); 161 | m_list.Hide(); 162 | //--- call method of the parent class 163 | return(CWnd::Show()); 164 | } 165 | //+------------------------------------------------------------------+ 166 | //| save | 167 | //+------------------------------------------------------------------+ 168 | bool CDatePicker::Save(const int file_handle) 169 | { 170 | //--- check 171 | if(file_handle==INVALID_HANDLE) 172 | return(false); 173 | //--- write 174 | FileWriteLong(file_handle,Value()); 175 | //--- succeed 176 | return(true); 177 | } 178 | //+------------------------------------------------------------------+ 179 | //| load | 180 | //+------------------------------------------------------------------+ 181 | bool CDatePicker::Load(const int file_handle) 182 | { 183 | //--- check 184 | if(file_handle==INVALID_HANDLE) 185 | return(false); 186 | //--- load 187 | if(!FileIsEnding(file_handle)) 188 | Value(FileReadLong(file_handle)); 189 | //--- succeed 190 | return(true); 191 | } 192 | //+------------------------------------------------------------------+ 193 | //| Handler of click on main entry field | 194 | //+------------------------------------------------------------------+ 195 | bool CDatePicker::OnClickEdit(void) 196 | { 197 | //--- change button state 198 | if(!m_drop.Pressed(!m_drop.Pressed())) 199 | return(false); 200 | //--- call the click on button handler 201 | return(OnClickButton()); 202 | } 203 | //+------------------------------------------------------------------+ 204 | //| Handler of click on button | 205 | //+------------------------------------------------------------------+ 206 | bool CDatePicker::OnClickButton(void) 207 | { 208 | //--- show or hide the drop-down list depending on the button state 209 | return((m_drop.Pressed()) ? ListShow():ListHide()); 210 | } 211 | //+------------------------------------------------------------------+ 212 | //| Handler of change on drop-down list | 213 | //+------------------------------------------------------------------+ 214 | bool CDatePicker::OnChangeList(void) 215 | { 216 | string text=TimeToString(m_value=m_list.Value(),TIME_DATE); 217 | //--- hide the list, depress the button 218 | ListHide(); 219 | m_drop.Pressed(false); 220 | //--- set text in the main entry field 221 | m_edit.Text(text); 222 | //--- send notification 223 | EventChartCustom(CONTROLS_SELF_MESSAGE,ON_CHANGE,m_id,0.0,m_name); 224 | //--- handled 225 | return(true); 226 | } 227 | //+------------------------------------------------------------------+ 228 | //| Show the drop-down list | 229 | //+------------------------------------------------------------------+ 230 | bool CDatePicker::ListShow(void) 231 | { 232 | //--- set value 233 | m_list.Value(m_value); 234 | //--- show the list 235 | return(m_list.Show()); 236 | } 237 | //+------------------------------------------------------------------+ 238 | //| Hide drop-down list | 239 | //+------------------------------------------------------------------+ 240 | bool CDatePicker::ListHide(void) 241 | { 242 | //--- hide the list 243 | return(m_list.Hide()); 244 | } 245 | //+------------------------------------------------------------------+ 246 | //| Hide the drop-down element if necessary | 247 | //+------------------------------------------------------------------+ 248 | void CDatePicker::CheckListHide(const int id,int x,int y) 249 | { 250 | //--- check event ID 251 | if(id!=CHARTEVENT_CLICK) 252 | return; 253 | //--- check visibility of the drop-down element 254 | if(!m_list.IsVisible()) 255 | return; 256 | //--- check mouse cursor's position 257 | y-=(int)ChartGetInteger(m_chart_id,CHART_WINDOW_YDISTANCE,m_subwin); 258 | if(!m_edit.Contains(x,y) && !m_list.Contains(x,y)) 259 | { 260 | m_drop.Pressed(false); 261 | m_list.Hide(); 262 | } 263 | } 264 | //+------------------------------------------------------------------+ 265 | -------------------------------------------------------------------------------- /Include/Trade/TerminalInfo.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| TerminalInfo.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include 7 | //+------------------------------------------------------------------+ 8 | //| Class CTerminalInfo. | 9 | //| Appointment: Class for access to terminal info. | 10 | //| Derives from class CObject. | 11 | //+------------------------------------------------------------------+ 12 | class CTerminalInfo : public CObject 13 | { 14 | public: 15 | CTerminalInfo(void); 16 | ~CTerminalInfo(void); 17 | //--- fast access methods to the integer terminal propertyes 18 | int Build(void) const; 19 | bool IsConnected(void) const; 20 | bool IsDLLsAllowed(void) const; 21 | bool IsTradeAllowed(void) const; 22 | bool IsEmailEnabled(void) const; 23 | bool IsFtpEnabled(void) const; 24 | int MaxBars(void) const; 25 | int CodePage(void) const; 26 | int CPUCores(void) const; 27 | int MemoryPhysical(void) const; 28 | int MemoryTotal(void) const; 29 | int MemoryAvailable(void) const; 30 | int MemoryUsed(void) const; 31 | bool IsX64(void) const; 32 | int OpenCLSupport(void) const; 33 | int DiskSpace(void) const; 34 | //--- fast access methods to the string terminal propertyes 35 | string Language(void) const; 36 | string Name(void) const; 37 | string Company(void) const; 38 | string Path(void) const; 39 | string DataPath(void) const; 40 | string CommonDataPath(void) const; 41 | //--- access methods to the API MQL5 functions 42 | long InfoInteger(const ENUM_TERMINAL_INFO_INTEGER prop_id) const; 43 | string InfoString(const ENUM_TERMINAL_INFO_STRING prop_id) const; 44 | }; 45 | //+------------------------------------------------------------------+ 46 | //| Constructor | 47 | //+------------------------------------------------------------------+ 48 | CTerminalInfo::CTerminalInfo(void) 49 | { 50 | } 51 | //+------------------------------------------------------------------+ 52 | //| Destructor | 53 | //+------------------------------------------------------------------+ 54 | CTerminalInfo::~CTerminalInfo(void) 55 | { 56 | } 57 | //+------------------------------------------------------------------+ 58 | //| Get the property value "TERMINAL_BUILD" | 59 | //+------------------------------------------------------------------+ 60 | int CTerminalInfo::Build(void) const 61 | { 62 | return((int)TerminalInfoInteger(TERMINAL_BUILD)); 63 | } 64 | //+------------------------------------------------------------------+ 65 | //| Get the property value "TERMINAL_CONNECTED" | 66 | //+------------------------------------------------------------------+ 67 | bool CTerminalInfo::IsConnected(void) const 68 | { 69 | return((bool)TerminalInfoInteger(TERMINAL_CONNECTED)); 70 | } 71 | //+------------------------------------------------------------------+ 72 | //| Get the property value "TERMINAL_DLLS_ALLOWED" | 73 | //+------------------------------------------------------------------+ 74 | bool CTerminalInfo::IsDLLsAllowed(void) const 75 | { 76 | return((bool)TerminalInfoInteger(TERMINAL_DLLS_ALLOWED)); 77 | } 78 | //+------------------------------------------------------------------+ 79 | //| Get the property value "TERMINAL_TRADE_ALLOWED" | 80 | //+------------------------------------------------------------------+ 81 | bool CTerminalInfo::IsTradeAllowed(void) const 82 | { 83 | return((bool)TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)); 84 | } 85 | //+------------------------------------------------------------------+ 86 | //| Get the property value "TERMINAL_EMAIL_ENABLED" | 87 | //+------------------------------------------------------------------+ 88 | bool CTerminalInfo::IsEmailEnabled(void) const 89 | { 90 | return((bool)TerminalInfoInteger(TERMINAL_EMAIL_ENABLED)); 91 | } 92 | //+------------------------------------------------------------------+ 93 | //| Get the property value "TERMINAL_FTP_ENABLED" | 94 | //+------------------------------------------------------------------+ 95 | bool CTerminalInfo::IsFtpEnabled(void) const 96 | { 97 | return((bool)TerminalInfoInteger(TERMINAL_FTP_ENABLED)); 98 | } 99 | //+------------------------------------------------------------------+ 100 | //| Get the property value "TERMINAL_MAXBARS" | 101 | //+------------------------------------------------------------------+ 102 | int CTerminalInfo::MaxBars(void) const 103 | { 104 | return((int)TerminalInfoInteger(TERMINAL_MAXBARS)); 105 | } 106 | //+------------------------------------------------------------------+ 107 | //| Get the property value "TERMINAL_CODEPAGE" | 108 | //+------------------------------------------------------------------+ 109 | int CTerminalInfo::CodePage(void) const 110 | { 111 | return((int)TerminalInfoInteger(TERMINAL_CODEPAGE)); 112 | } 113 | //+------------------------------------------------------------------+ 114 | //| Get the property value "TERMINAL_CPU_CORES" | 115 | //+------------------------------------------------------------------+ 116 | int CTerminalInfo::CPUCores(void) const 117 | { 118 | return((int)TerminalInfoInteger(TERMINAL_CPU_CORES)); 119 | } 120 | //+------------------------------------------------------------------+ 121 | //| Get the property value "TERMINAL_MEMORY_PHYSICAL" | 122 | //+------------------------------------------------------------------+ 123 | int CTerminalInfo::MemoryPhysical(void) const 124 | { 125 | return((int)TerminalInfoInteger(TERMINAL_MEMORY_PHYSICAL)); 126 | } 127 | //+------------------------------------------------------------------+ 128 | //| Get the property value "TERMINAL_MEMORY_TOTAL" | 129 | //+------------------------------------------------------------------+ 130 | int CTerminalInfo::MemoryTotal(void) const 131 | { 132 | return((int)TerminalInfoInteger(TERMINAL_MEMORY_TOTAL)); 133 | } 134 | //+------------------------------------------------------------------+ 135 | //| Get the property value "TERMINAL_MEMORY_AVAILABLE" | 136 | //+------------------------------------------------------------------+ 137 | int CTerminalInfo::MemoryAvailable(void) const 138 | { 139 | return((int)TerminalInfoInteger(TERMINAL_MEMORY_AVAILABLE)); 140 | } 141 | //+------------------------------------------------------------------+ 142 | //| Get the property value "TERMINAL_MEMORY_USED" | 143 | //+------------------------------------------------------------------+ 144 | int CTerminalInfo::MemoryUsed(void) const 145 | { 146 | return((int)TerminalInfoInteger(TERMINAL_MEMORY_USED)); 147 | } 148 | //+------------------------------------------------------------------+ 149 | //| Get the property value "TERMINAL_X64" | 150 | //+------------------------------------------------------------------+ 151 | bool CTerminalInfo::IsX64(void) const 152 | { 153 | return((bool)TerminalInfoInteger(TERMINAL_X64)); 154 | } 155 | //+------------------------------------------------------------------+ 156 | //| Get the property value "TERMINAL_OPENCL_SUPPORT" | 157 | //+------------------------------------------------------------------+ 158 | int CTerminalInfo::OpenCLSupport(void) const 159 | { 160 | return((int)TerminalInfoInteger(TERMINAL_OPENCL_SUPPORT)); 161 | } 162 | //+------------------------------------------------------------------+ 163 | //| Get the property value "TERMINAL_DISK_SPACE" | 164 | //+------------------------------------------------------------------+ 165 | int CTerminalInfo::DiskSpace(void) const 166 | { 167 | return((int)TerminalInfoInteger(TERMINAL_DISK_SPACE)); 168 | } 169 | //+------------------------------------------------------------------+ 170 | //| Get the property value "TERMINAL_LANGUAGE" | 171 | //+------------------------------------------------------------------+ 172 | string CTerminalInfo::Language(void) const 173 | { 174 | return(TerminalInfoString(TERMINAL_LANGUAGE)); 175 | } 176 | //+------------------------------------------------------------------+ 177 | //| Get the property value "TERMINAL_NAME" | 178 | //+------------------------------------------------------------------+ 179 | string CTerminalInfo::Name(void) const 180 | { 181 | return(TerminalInfoString(TERMINAL_NAME)); 182 | } 183 | //+------------------------------------------------------------------+ 184 | //| Get the property value "TERMINAL_COMPANY" | 185 | //+------------------------------------------------------------------+ 186 | string CTerminalInfo::Company(void) const 187 | { 188 | return(TerminalInfoString(TERMINAL_COMPANY)); 189 | } 190 | //+------------------------------------------------------------------+ 191 | //| Get the property value "TERMINAL_PATH" | 192 | //+------------------------------------------------------------------+ 193 | string CTerminalInfo::Path(void) const 194 | { 195 | return(TerminalInfoString(TERMINAL_PATH)); 196 | } 197 | //+------------------------------------------------------------------+ 198 | //| Get the property value "TERMINAL_DATA_PATH" | 199 | //+------------------------------------------------------------------+ 200 | string CTerminalInfo::DataPath(void) const 201 | { 202 | return(TerminalInfoString(TERMINAL_DATA_PATH)); 203 | } 204 | //+------------------------------------------------------------------+ 205 | //| Get the property value "TERMINAL_COMMONDATA_PATH" | 206 | //+------------------------------------------------------------------+ 207 | string CTerminalInfo::CommonDataPath(void) const 208 | { 209 | return(TerminalInfoString(TERMINAL_COMMONDATA_PATH)); 210 | } 211 | //+------------------------------------------------------------------+ 212 | //| Access functions AccountInfoInteger(...) | 213 | //+------------------------------------------------------------------+ 214 | long CTerminalInfo::InfoInteger(const ENUM_TERMINAL_INFO_INTEGER prop_id) const 215 | { 216 | return(TerminalInfoInteger(prop_id)); 217 | } 218 | //+------------------------------------------------------------------+ 219 | //| Access functions AccountInfoString(...) | 220 | //+------------------------------------------------------------------+ 221 | string CTerminalInfo::InfoString(const ENUM_TERMINAL_INFO_STRING prop_id) const 222 | { 223 | return(TerminalInfoString(prop_id)); 224 | } 225 | //+------------------------------------------------------------------+ 226 | -------------------------------------------------------------------------------- /Include/Controls/Rect.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Rect.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | //+------------------------------------------------------------------+ 7 | //| Structure CPoint | 8 | //| Usage: point of chart in Cartesian coordinates | 9 | //+------------------------------------------------------------------+ 10 | struct CPoint 11 | { 12 | int x; // horizontal coordinate 13 | int y; // vertical coordinate 14 | }; 15 | //+------------------------------------------------------------------+ 16 | //| Structure CSize | 17 | //| Usage: size of area of chart in Cartesian coordinates | 18 | //+------------------------------------------------------------------+ 19 | struct CSize 20 | { 21 | int cx; // horizontal size 22 | int cy; // vertical size 23 | }; 24 | //+------------------------------------------------------------------+ 25 | //| Structure CRect | 26 | //| Usage: area of chart in Cartesian coordinates | 27 | //+------------------------------------------------------------------+ 28 | struct CRect 29 | { 30 | int left; // left coordinate 31 | int top; // top coordinate 32 | int right; // right coordinate 33 | int bottom; // bottom coordinate 34 | 35 | //--- methods 36 | CPoint LeftTop(void) const; 37 | void LeftTop(const int x,const int y); 38 | void LeftTop(const CPoint& point); 39 | CPoint RightBottom(void) const; 40 | void RightBottom(const int x,const int y); 41 | void RightBottom(const CPoint& point); 42 | CPoint CenterPoint(void) const; 43 | int Width(void) const { return(right-left); } 44 | void Width(const int w) { right=left+w; } 45 | int Height(void) const { return(bottom-top); } 46 | void Height(const int h) { bottom=top+h; } 47 | CSize Size(void) const; 48 | void Size(const int cx,const int cy); 49 | void Size(const CSize& size); 50 | void SetBound(const int l,const int t,const int r,const int b); 51 | void SetBound(const CRect& rect); 52 | void SetBound(const CPoint& point,const CSize& size); 53 | void SetBound(const CPoint& left_top,const CPoint& right_bottom); 54 | void Move(const int x,const int y); 55 | void Move(const CPoint& point); 56 | void Shift(const int dx,const int dy); 57 | void Shift(const CPoint& point); 58 | void Shift(const CSize& size); 59 | bool Contains(const int x,const int y) const; 60 | bool Contains(const CPoint& point) const; 61 | void Normalize(void); 62 | }; 63 | //+------------------------------------------------------------------+ 64 | //| Get parameters of area | 65 | //+------------------------------------------------------------------+ 66 | CPoint CRect::LeftTop(void) const 67 | { 68 | CPoint point; 69 | //--- action 70 | point.x=left; 71 | point.y=top; 72 | //--- result 73 | return(point); 74 | } 75 | //+------------------------------------------------------------------+ 76 | //| Set parameters of area | 77 | //+------------------------------------------------------------------+ 78 | void CRect::LeftTop(const int x,const int y) 79 | { 80 | left=x; 81 | top =y; 82 | } 83 | //+------------------------------------------------------------------+ 84 | //| Set parameters of area | 85 | //+------------------------------------------------------------------+ 86 | void CRect::LeftTop(const CPoint& point) 87 | { 88 | left=point.x; 89 | top =point.y; 90 | } 91 | //+------------------------------------------------------------------+ 92 | //| Get parameters of area | 93 | //+------------------------------------------------------------------+ 94 | CPoint CRect::RightBottom(void) const 95 | { 96 | CPoint point; 97 | //--- action 98 | point.x=right; 99 | point.y=bottom; 100 | //--- result 101 | return(point); 102 | } 103 | //+------------------------------------------------------------------+ 104 | //| Set parameters of area | 105 | //+------------------------------------------------------------------+ 106 | void CRect::RightBottom(const int x,const int y) 107 | { 108 | right =x; 109 | bottom=y; 110 | } 111 | //+------------------------------------------------------------------+ 112 | //| Set parameters of area | 113 | //+------------------------------------------------------------------+ 114 | void CRect::RightBottom(const CPoint& point) 115 | { 116 | right =point.x; 117 | bottom=point.y; 118 | } 119 | //+------------------------------------------------------------------+ 120 | //| Get parameters of area | 121 | //+------------------------------------------------------------------+ 122 | CPoint CRect::CenterPoint(void) const 123 | { 124 | CPoint point; 125 | //--- action 126 | point.x=left+Width()/2; 127 | point.y=top+Height()/2; 128 | //--- result 129 | return(point); 130 | } 131 | //+------------------------------------------------------------------+ 132 | //| Get parameters of area | 133 | //+------------------------------------------------------------------+ 134 | CSize CRect::Size(void) const 135 | { 136 | CSize size; 137 | //--- action 138 | size.cx=right-left; 139 | size.cy=bottom-top; 140 | //--- result 141 | return(size); 142 | } 143 | //+------------------------------------------------------------------+ 144 | //| Set parameters of area | 145 | //+------------------------------------------------------------------+ 146 | void CRect::Size(const int cx,const int cy) 147 | { 148 | right =left+cx; 149 | bottom=top+cy; 150 | } 151 | //+------------------------------------------------------------------+ 152 | //| Set parameters of area | 153 | //+------------------------------------------------------------------+ 154 | void CRect::Size(const CSize& size) 155 | { 156 | right =left+size.cx; 157 | bottom=top+size.cy; 158 | } 159 | //+------------------------------------------------------------------+ 160 | //| Set parameters of area | 161 | //+------------------------------------------------------------------+ 162 | void CRect::SetBound(const int l,const int t,const int r,const int b) 163 | { 164 | left =l; 165 | top =t; 166 | right =r; 167 | bottom=b; 168 | } 169 | //+------------------------------------------------------------------+ 170 | //| Set parameters of area | 171 | //+------------------------------------------------------------------+ 172 | void CRect::SetBound(const CRect& rect) 173 | { 174 | left =rect.left; 175 | top =rect.top; 176 | right =rect.right; 177 | bottom=rect.bottom; 178 | } 179 | //+------------------------------------------------------------------+ 180 | //| Set parameters of area | 181 | //+------------------------------------------------------------------+ 182 | void CRect::SetBound(const CPoint& point,const CSize& size) 183 | { 184 | LeftTop(point); 185 | Size(size); 186 | } 187 | //+------------------------------------------------------------------+ 188 | //| Set parameters of area | 189 | //+------------------------------------------------------------------+ 190 | void CRect::SetBound(const CPoint& left_top,const CPoint& right_bottom) 191 | { 192 | LeftTop(left_top); 193 | RightBottom(right_bottom); 194 | } 195 | //+------------------------------------------------------------------+ 196 | //| Absolute movement of area | 197 | //+------------------------------------------------------------------+ 198 | void CRect::Move(const int x,const int y) 199 | { 200 | right +=x-left; 201 | bottom+=y-top; 202 | left =x; 203 | top =y; 204 | } 205 | //+------------------------------------------------------------------+ 206 | //| Absolute movement of area | 207 | //+------------------------------------------------------------------+ 208 | void CRect::Move(const CPoint& point) 209 | { 210 | right +=point.x-left; 211 | bottom+=point.y-top; 212 | left =point.x; 213 | top =point.y; 214 | } 215 | //+------------------------------------------------------------------+ 216 | //| Relative movement of area | 217 | //+------------------------------------------------------------------+ 218 | void CRect::Shift(const int dx,const int dy) 219 | { 220 | left +=dx; 221 | top +=dy; 222 | right +=dx; 223 | bottom+=dy; 224 | } 225 | //+------------------------------------------------------------------+ 226 | //| Relative movement of area | 227 | //+------------------------------------------------------------------+ 228 | void CRect::Shift(const CPoint& point) 229 | { 230 | left +=point.x; 231 | top +=point.y; 232 | right +=point.x; 233 | bottom+=point.y; 234 | } 235 | //+------------------------------------------------------------------+ 236 | //| Relative movement of area | 237 | //+------------------------------------------------------------------+ 238 | void CRect::Shift(const CSize& size) 239 | { 240 | left +=size.cx; 241 | top +=size.cy; 242 | right +=size.cx; 243 | bottom+=size.cy; 244 | } 245 | //+------------------------------------------------------------------+ 246 | //| Check if a point is within the area | 247 | //+------------------------------------------------------------------+ 248 | bool CRect::Contains(const int x,const int y) const 249 | { 250 | //--- check and return the result 251 | return(x>=left && x<=right && y>=top && y<=bottom); 252 | } 253 | //+------------------------------------------------------------------+ 254 | //| Check if a point is within the area | 255 | //+------------------------------------------------------------------+ 256 | bool CRect::Contains(const CPoint& point) const 257 | { 258 | //--- check and return the result 259 | return(point.x>=left && point.x<=right && point.y>=top && point.y<=bottom); 260 | } 261 | //+------------------------------------------------------------------+ 262 | //| Standardizes the height and width | 263 | //+------------------------------------------------------------------+ 264 | void CRect::Normalize(void) 265 | { 266 | if(left>right) 267 | { 268 | int tmp=left; 269 | left=right; 270 | right=tmp; 271 | } 272 | if(top>bottom) 273 | { 274 | int tmp=top; 275 | top=bottom; 276 | bottom=tmp; 277 | } 278 | } 279 | //+------------------------------------------------------------------+ 280 | -------------------------------------------------------------------------------- /Include/ChartObjects/ChartObjectsChannels.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| ChartObjectsChannels.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | //| All channels. | 7 | //+------------------------------------------------------------------+ 8 | #include "ChartObjectsLines.mqh" 9 | //+------------------------------------------------------------------+ 10 | //| Class CChartObjectChannel. | 11 | //| Purpose: Class of the "Equidistant channel" object of chart. | 12 | //| Derives from class CChartObjectTrend. | 13 | //+------------------------------------------------------------------+ 14 | class CChartObjectChannel : public CChartObjectTrend 15 | { 16 | public: 17 | CChartObjectChannel(void); 18 | ~CChartObjectChannel(void); 19 | //--- method of creating the object 20 | bool Create(long chart_id,const string name,const int window, 21 | const datetime time1,const double price1, 22 | const datetime time2,const double price2, 23 | const datetime time3,const double price3); 24 | //--- method of identifying the object 25 | virtual int Type(void) const { return(OBJ_CHANNEL); } 26 | }; 27 | //+------------------------------------------------------------------+ 28 | //| Constructor | 29 | //+------------------------------------------------------------------+ 30 | CChartObjectChannel::CChartObjectChannel(void) 31 | { 32 | } 33 | //+------------------------------------------------------------------+ 34 | //| Destructor | 35 | //+------------------------------------------------------------------+ 36 | CChartObjectChannel::~CChartObjectChannel(void) 37 | { 38 | } 39 | //+------------------------------------------------------------------+ 40 | //| Create object "Equidistant channel" | 41 | //+------------------------------------------------------------------+ 42 | bool CChartObjectChannel::Create(long chart_id,const string name,const int window, 43 | const datetime time1,const double price1, 44 | const datetime time2,const double price2, 45 | const datetime time3,const double price3) 46 | { 47 | if(!ObjectCreate(chart_id,name,OBJ_CHANNEL,window,time1,price1,time2,price2,time3,price3)) 48 | return(false); 49 | if(!Attach(chart_id,name,window,3)) 50 | return(false); 51 | //--- successful 52 | return(true); 53 | } 54 | //+------------------------------------------------------------------+ 55 | //| Class CChartObjectStdDevChannel. | 56 | //| Purpose: Class of the "Standrad deviation channel" | 57 | //| object of chart. | 58 | //| Derives from class CChartObjectTrend. | 59 | //+------------------------------------------------------------------+ 60 | class CChartObjectStdDevChannel : public CChartObjectTrend 61 | { 62 | public: 63 | CChartObjectStdDevChannel(void); 64 | ~CChartObjectStdDevChannel(void); 65 | //--- methods of access to properties of the object 66 | double Deviations(void) const; 67 | bool Deviations(const double deviation) const; 68 | //--- method of creating the object 69 | bool Create(long chart_id,const string name,const int window, 70 | const datetime time1,const datetime time2,const double deviation); 71 | //--- method of identifying the object 72 | virtual int Type(void) const { return(OBJ_STDDEVCHANNEL); } 73 | //--- methods for working with files 74 | virtual bool Save(const int file_handle); 75 | virtual bool Load(const int file_handle); 76 | }; 77 | //+------------------------------------------------------------------+ 78 | //| Constructor | 79 | //+------------------------------------------------------------------+ 80 | CChartObjectStdDevChannel::CChartObjectStdDevChannel(void) 81 | { 82 | } 83 | //+------------------------------------------------------------------+ 84 | //| Destructor | 85 | //+------------------------------------------------------------------+ 86 | CChartObjectStdDevChannel::~CChartObjectStdDevChannel(void) 87 | { 88 | } 89 | //+------------------------------------------------------------------+ 90 | //| Create object "Standard deviation channel" | 91 | //+------------------------------------------------------------------+ 92 | bool CChartObjectStdDevChannel::Create(long chart_id,const string name,const int window, 93 | const datetime time1,const datetime time2,const double deviation) 94 | { 95 | if(!ObjectCreate(chart_id,name,OBJ_STDDEVCHANNEL,window,time1,0.0,time2,0.0)) 96 | return(false); 97 | if(!Attach(chart_id,name,window,2)) 98 | return(false); 99 | if(!Deviations(deviation)) 100 | return(false); 101 | //--- successful 102 | return(true); 103 | } 104 | //+------------------------------------------------------------------+ 105 | //| Get value of the "Deviations" property | 106 | //+------------------------------------------------------------------+ 107 | double CChartObjectStdDevChannel::Deviations(void) const 108 | { 109 | //--- check 110 | if(m_chart_id==-1) 111 | return(EMPTY_VALUE); 112 | //--- result 113 | return(ObjectGetDouble(m_chart_id,m_name,OBJPROP_DEVIATION)); 114 | } 115 | //+------------------------------------------------------------------+ 116 | //| Set value for the "Deviations" property | 117 | //+------------------------------------------------------------------+ 118 | bool CChartObjectStdDevChannel::Deviations(const double deviation) const 119 | { 120 | //--- check 121 | if(m_chart_id==-1) 122 | return(false); 123 | //--- result 124 | return(ObjectSetDouble(m_chart_id,m_name,OBJPROP_DEVIATION,deviation)); 125 | } 126 | //+------------------------------------------------------------------+ 127 | //| Writing parameters of object to file | 128 | //+------------------------------------------------------------------+ 129 | bool CChartObjectStdDevChannel::Save(const int file_handle) 130 | { 131 | //--- check 132 | if(file_handle==INVALID_HANDLE || m_chart_id==-1) 133 | return(false); 134 | //--- write 135 | if(!CChartObjectTrend::Save(file_handle)) 136 | return(false); 137 | //--- write value of the "Deviations" property 138 | if(FileWriteDouble(file_handle,ObjectGetDouble(m_chart_id,m_name,OBJPROP_DEVIATION))!=sizeof(double)) 139 | return(false); 140 | //--- successful 141 | return(true); 142 | } 143 | //+------------------------------------------------------------------+ 144 | //| Reading parameters of object from file | 145 | //+------------------------------------------------------------------+ 146 | bool CChartObjectStdDevChannel::Load(const int file_handle) 147 | { 148 | //--- check 149 | if(file_handle==INVALID_HANDLE || m_chart_id==-1) 150 | return(false); 151 | //--- read 152 | if(!CChartObjectTrend::Load(file_handle)) 153 | return(false); 154 | //--- read value of the "Deviations" property 155 | if(!ObjectSetDouble(m_chart_id,m_name,OBJPROP_DEVIATION,FileReadDouble(file_handle))) 156 | return(false); 157 | //--- successful 158 | return(true); 159 | } 160 | //+------------------------------------------------------------------+ 161 | //| Class CChartObjectRegression. | 162 | //| Purpose: Class of the "Regression channel" object of chart. | 163 | //| Derives from class CChartObjectTrend. | 164 | //+------------------------------------------------------------------+ 165 | class CChartObjectRegression : public CChartObjectTrend 166 | { 167 | public: 168 | CChartObjectRegression(void); 169 | ~CChartObjectRegression(void); 170 | //--- method of creating the object 171 | bool Create(long chart_id,const string name,const int window, 172 | const datetime time1,const datetime time2); 173 | //--- method of identifying the object 174 | virtual int Type(void) const { return(OBJ_REGRESSION); } 175 | }; 176 | //+------------------------------------------------------------------+ 177 | //| Constructor | 178 | //+------------------------------------------------------------------+ 179 | CChartObjectRegression::CChartObjectRegression(void) 180 | { 181 | } 182 | //+------------------------------------------------------------------+ 183 | //| Destructor | 184 | //+------------------------------------------------------------------+ 185 | CChartObjectRegression::~CChartObjectRegression(void) 186 | { 187 | } 188 | //+------------------------------------------------------------------+ 189 | //| Create object "Regression channel" | 190 | //+------------------------------------------------------------------+ 191 | bool CChartObjectRegression::Create(long chart_id,const string name,const int window, 192 | const datetime time1,const datetime time2) 193 | { 194 | if(!ObjectCreate(chart_id,name,OBJ_REGRESSION,window,time1,0.0,time2,0.0)) 195 | return(false); 196 | if(!Attach(chart_id,name,window,2)) 197 | return(false); 198 | //--- successful 199 | return(true); 200 | } 201 | //+------------------------------------------------------------------+ 202 | //| Class CChartObjectPitchfork. | 203 | //| Purpose: Class of the "Andrews pitchfork" object of chart | 204 | //| Derives from class CChartObjectTrend. | 205 | //+------------------------------------------------------------------+ 206 | class CChartObjectPitchfork : public CChartObjectTrend 207 | { 208 | public: 209 | CChartObjectPitchfork(void); 210 | ~CChartObjectPitchfork(void); 211 | //--- method of creating the object 212 | bool Create(long chart_id,const string name,const int window, 213 | const datetime time1,const double price1, 214 | const datetime time2,const double price2, 215 | const datetime time3,const double price3); 216 | //--- method of identifying the object 217 | virtual int Type(void) const { return(OBJ_CHANNEL); } 218 | }; 219 | //+------------------------------------------------------------------+ 220 | //| Constructor | 221 | //+------------------------------------------------------------------+ 222 | CChartObjectPitchfork::CChartObjectPitchfork(void) 223 | { 224 | } 225 | //+------------------------------------------------------------------+ 226 | //| Destructor | 227 | //+------------------------------------------------------------------+ 228 | CChartObjectPitchfork::~CChartObjectPitchfork(void) 229 | { 230 | } 231 | //+------------------------------------------------------------------+ 232 | //| Create object "Andrews pitchfork" | 233 | //+------------------------------------------------------------------+ 234 | bool CChartObjectPitchfork::Create(long chart_id,const string name,const int window, 235 | const datetime time1,const double price1, 236 | const datetime time2,const double price2, 237 | const datetime time3,const double price3) 238 | { 239 | if(!ObjectCreate(chart_id,name,OBJ_PITCHFORK,window,time1,price1,time2,price2,time3,price3)) 240 | return(false); 241 | if(!Attach(chart_id,name,window,3)) 242 | return(false); 243 | //--- successful 244 | return(true); 245 | } 246 | //+------------------------------------------------------------------+ 247 | -------------------------------------------------------------------------------- /Include/Controls/Defines.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Defines.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | //+------------------------------------------------------------------+ 7 | //| Enumerations | 8 | //+------------------------------------------------------------------+ 9 | //--- properties flags 10 | enum ENUM_WND_PROP_FLAGS 11 | { 12 | WND_PROP_FLAG_CAN_DBL_CLICK = 1, // can be double clicked by mouse 13 | WND_PROP_FLAG_CAN_DRAG = 2, // can be dragged by mouse 14 | WND_PROP_FLAG_CLICKS_BY_PRESS= 4, // generates the "click" event series on pressing left mouse button 15 | WND_PROP_FLAG_CAN_LOCK = 8, // control with fixed state (usually it is a button) 16 | WND_PROP_FLAG_READ_ONLY =16 // read only (usually it is a edit) 17 | }; 18 | //--- state flags 19 | enum ENUM_WND_STATE_FLAGS 20 | { 21 | WND_STATE_FLAG_ENABLE = 1, // "object is enabled" flag 22 | WND_STATE_FLAG_VISIBLE = 2, // "object is visible" flag 23 | WND_STATE_FLAG_ACTIVE = 4, // "object is active" flag 24 | }; 25 | //--- mouse flags 26 | enum ENUM_MOUSE_FLAGS 27 | { 28 | MOUSE_INVALID_FLAGS =-1, // no buttons state 29 | MOUSE_EMPTY = 0, // buttons are not pressed 30 | MOUSE_LEFT = 1, // left button pressed 31 | MOUSE_RIGHT = 2 // right button pressed 32 | }; 33 | //--- alignment flags 34 | enum ENUM_WND_ALIGN_FLAGS 35 | { 36 | WND_ALIGN_NONE = 0, // no alignment 37 | WND_ALIGN_LEFT = 1, // align by left border 38 | WND_ALIGN_TOP = 2, // align by top border 39 | WND_ALIGN_RIGHT = 4, // align by right border 40 | WND_ALIGN_BOTTOM = 8, // align by bottom border 41 | WND_ALIGN_WIDTH = WND_ALIGN_LEFT|WND_ALIGN_RIGHT, // justify 42 | WND_ALIGN_HEIGHT = WND_ALIGN_TOP|WND_ALIGN_BOTTOM, // align by top and bottom border 43 | WND_ALIGN_CLIENT = WND_ALIGN_WIDTH|WND_ALIGN_HEIGHT // align by all sides 44 | }; 45 | //+------------------------------------------------------------------+ 46 | //| Drawing styles and colors | 47 | //+------------------------------------------------------------------+ 48 | //--- common 49 | #define CONTROLS_FONT_NAME "Trebuchet MS" 50 | #define CONTROLS_FONT_SIZE (10) 51 | //--- Text 52 | #define CONTROLS_COLOR_TEXT C'0x3B,0x29,0x28' 53 | #define CONTROLS_COLOR_TEXT_SEL White 54 | #define CONTROLS_COLOR_BG White 55 | #define CONTROLS_COLOR_BG_SEL C'0x33,0x99,0xFF' 56 | //--- Button 57 | #define CONTROLS_BUTTON_COLOR C'0x3B,0x29,0x28' 58 | #define CONTROLS_BUTTON_COLOR_BG C'0xDD,0xE2,0xEB' 59 | #define CONTROLS_BUTTON_COLOR_BORDER C'0xB2,0xC3,0xCF' 60 | //--- Label 61 | #define CONTROLS_LABEL_COLOR C'0x3B,0x29,0x28' 62 | //--- Edit 63 | #define CONTROLS_EDIT_COLOR C'0x3B,0x29,0x28' 64 | #define CONTROLS_EDIT_COLOR_BG White 65 | #define CONTROLS_EDIT_COLOR_BORDER C'0xB2,0xC3,0xCF' 66 | //--- Scrolls 67 | #define CONTROLS_SCROLL_COLOR_BG C'0xEC,0xEC,0xEC' 68 | #define CONTROLS_SCROLL_COLOR_BORDER C'0xD3,0xD3,0xD3' 69 | //--- Client 70 | #define CONTROLS_CLIENT_COLOR_BG C'0xDE,0xDE,0xDE' 71 | #define CONTROLS_CLIENT_COLOR_BORDER C'0x2C,0x2C,0x2C' 72 | //--- ListView 73 | #define CONTROLS_LISTITEM_COLOR_TEXT C'0x3B,0x29,0x28' 74 | #define CONTROLS_LISTITEM_COLOR_TEXT_SEL White 75 | #define CONTROLS_LISTITEM_COLOR_BG White 76 | #define CONTROLS_LISTITEM_COLOR_BG_SEL C'0x33,0x99,0xFF' 77 | #define CONTROLS_LIST_COLOR_BG White 78 | #define CONTROLS_LIST_COLOR_BORDER C'0xB2,0xC3,0xCF' 79 | //--- CheckGroup 80 | #define CONTROLS_CHECKGROUP_COLOR_BG C'0xF7,0xF7,0xF7' 81 | #define CONTROLS_CHECKGROUP_COLOR_BORDER C'0xB2,0xC3,0xCF' 82 | //--- RadioGroup 83 | #define CONTROLS_RADIOGROUP_COLOR_BG C'0xF7,0xF7,0xF7' 84 | #define CONTROLS_RADIOGROUP_COLOR_BORDER C'0xB2,0xC3,0xCF' 85 | //--- Dialog 86 | #define CONTROLS_DIALOG_COLOR_BORDER_LIGHT White 87 | #define CONTROLS_DIALOG_COLOR_BORDER_DARK C'0xB6,0xB6,0xB6' 88 | #define CONTROLS_DIALOG_COLOR_BG C'0xF0,0xF0,0xF0' 89 | #define CONTROLS_DIALOG_COLOR_CAPTION_TEXT C'0x28,0x29,0x3B' 90 | #define CONTROLS_DIALOG_COLOR_CLIENT_BG C'0xF7,0xF7,0xF7' 91 | #define CONTROLS_DIALOG_COLOR_CLIENT_BORDER C'0xC8,0xC8,0xC8' 92 | //+------------------------------------------------------------------+ 93 | //| Constants for the controls | 94 | //+------------------------------------------------------------------+ 95 | //--- common 96 | #define CONTROLS_INVALID_ID (-1) // invalid ID 97 | #define CONTROLS_INVALID_INDEX (-1) // invalid index of array 98 | #define CONTROLS_SELF_MESSAGE (-1) // message to oneself 99 | #define CONTROLS_MAXIMUM_ID (10000) // maximum number of IDs in application 100 | #define CONTROLS_BORDER_WIDTH (1) // border width 101 | #define CONTROLS_SUBWINDOW_GAP (3) // gap between sub-windows along the Y axis 102 | #define CONTROLS_DRAG_SPACING (50) // sensitivity threshold for dragging 103 | #define CONTROLS_DBL_CLICK_TIME (100) // double click interval 104 | //--- BmpButton 105 | #define CONTROLS_BUTTON_SIZE (16) // default size of button (16 x 16) 106 | //--- Scrolls 107 | #define CONTROLS_SCROLL_SIZE (18) // default lateral size of scrollbar 108 | #define CONTROLS_SCROLL_THUMB_SIZE (22) // default length of scroll box 109 | //--- RadioButton 110 | #define CONTROLS_RADIO_BUTTON_X_OFF (3) // X offset of radio button (for RadioButton) 111 | #define CONTROLS_RADIO_BUTTON_Y_OFF (3) // Y offset of radio button (for RadioButton) 112 | #define CONTROLS_RADIO_LABEL_X_OFF (20) // X offset of label (for RadioButton) 113 | #define CONTROLS_RADIO_LABEL_Y_OFF (0) // Y offset of label (for RadioButton) 114 | //--- CheckBox 115 | #define CONTROLS_CHECK_BUTTON_X_OFF (3) // X offset of check button (for CheckBox) 116 | #define CONTROLS_CHECK_BUTTON_Y_OFF (3) // Y offset of check button (for CheckBox) 117 | #define CONTROLS_CHECK_LABEL_X_OFF (20) // X offset of label (for CheckBox) 118 | #define CONTROLS_CHECK_LABEL_Y_OFF (0) // Y offset of label (for CheckBox) 119 | //--- Spin 120 | #define CONTROLS_SPIN_BUTTON_X_OFF (2) // X offset of button from right (for SpinEdit) 121 | #define CONTROLS_SPIN_MIN_HEIGHT (18) // minimal height (for SpinEdit) 122 | #define CONTROLS_SPIN_BUTTON_SIZE (8) // default size of button (16 x 8) (for SpinEdit) 123 | //--- Combo 124 | #define CONTROLS_COMBO_BUTTON_X_OFF (2) // X offset of button from right (for ComboBox) 125 | #define CONTROLS_COMBO_MIN_HEIGHT (18) // minimal height (for ComboBox) 126 | #define CONTROLS_COMBO_ITEM_HEIGHT (18) // height of combo box item (for ComboBox) 127 | #define CONTROLS_COMBO_ITEMS_VIEW (8) // number of items in combo box (for ComboBox) 128 | //--- ListView 129 | #define CONTROLS_LIST_ITEM_HEIGHT (18) // height of list item (for ListView) 130 | //--- Dialog 131 | #define CONTROLS_DIALOG_CAPTION_HEIGHT (22) // height of dialog header 132 | #define CONTROLS_DIALOG_BUTTON_OFF (3) // offset of dialog buttons 133 | #define CONTROLS_DIALOG_CLIENT_OFF (2) // offset of dialog client area 134 | #define CONTROLS_DIALOG_MINIMIZE_LEFT (10) // left coordinate of dialog in minimized state 135 | #define CONTROLS_DIALOG_MINIMIZE_TOP (10) // top coordinate of dialog in minimized state 136 | #define CONTROLS_DIALOG_MINIMIZE_WIDTH (100) // width of dialog in minimized state 137 | #define CONTROLS_DIALOG_MINIMIZE_HEIGHT (4*CONTROLS_BORDER_WIDTH+CONTROLS_DIALOG_CAPTION_HEIGHT) // height of dialog in minimized state 138 | //+------------------------------------------------------------------+ 139 | //| Macro | 140 | //+------------------------------------------------------------------+ 141 | //--- check properties 142 | #define IS_CAN_DBL_CLICK ((m_prop_flags&WND_PROP_FLAG_CAN_DBL_CLICK)!=0) 143 | #define IS_CAN_DRAG ((m_prop_flags&WND_PROP_FLAG_CAN_DRAG)!=0) 144 | #define IS_CLICKS_BY_PRESS ((m_prop_flags&WND_PROP_FLAG_CLICKS_BY_PRESS)!=0) 145 | #define IS_CAN_LOCK ((m_prop_flags&WND_PROP_FLAG_CAN_LOCK)!=0) 146 | #define IS_READ_ONLY ((m_prop_flags&WND_PROP_FLAG_READ_ONLY)!=0) 147 | //--- check state 148 | #define IS_ENABLED ((m_state_flags&WND_STATE_FLAG_ENABLE)!=0) 149 | #define IS_VISIBLE ((m_state_flags&WND_STATE_FLAG_VISIBLE)!=0) 150 | #define IS_ACTIVE ((m_state_flags&WND_STATE_FLAG_ACTIVE)!=0) 151 | //+------------------------------------------------------------------+ 152 | //| Macro of event handling map | 153 | //+------------------------------------------------------------------+ 154 | #define INTERNAL_EVENT (-1) 155 | //--- beginning of map 156 | #define EVENT_MAP_BEGIN(class_name) bool class_name::OnEvent(const int id,const long& lparam,const double& dparam,const string& sparam) { 157 | //--- end of map 158 | #define EVENT_MAP_END(parent_class_name) return(parent_class_name::OnEvent(id,lparam,dparam,sparam)); } 159 | //--- event handling by numeric ID 160 | #define ON_EVENT(event,control,handler) if(id==(event+CHARTEVENT_CUSTOM) && lparam==control.Id()) { handler(); return(true); } 161 | //--- event handling by numeric ID by pointer of control 162 | #define ON_EVENT_PTR(event,control,handler) if(control!=NULL && id==(event+CHARTEVENT_CUSTOM) && lparam==control.Id()) { handler(); return(true); } 163 | //--- event handling without ID analysis 164 | #define ON_NO_ID_EVENT(event,handler) if(id==(event+CHARTEVENT_CUSTOM)) { return(handler()); } 165 | //--- event handling by row ID 166 | #define ON_NAMED_EVENT(event,control,handler) if(id==(event+CHARTEVENT_CUSTOM) && sparam==control.Name()) { handler(); return(true); } 167 | //--- handling of indexed event 168 | #define ON_INDEXED_EVENT(event,controls,handler) { int total=ArraySize(controls); for(int i=0;i 7 | //+------------------------------------------------------------------+ 8 | //| Class CFile. | 9 | //| Purpose: Base class of file operations. | 10 | //| Derives from class CObject. | 11 | //+------------------------------------------------------------------+ 12 | class CFile : public CObject 13 | { 14 | protected: 15 | int m_handle; // handle of file 16 | string m_name; // name of opened file 17 | int m_flags; // flags of opened file 18 | 19 | public: 20 | CFile(void); 21 | ~CFile(void); 22 | //--- methods of access to protected data 23 | int Handle(void) const { return(m_handle); }; 24 | string FileName(void) const { return(m_name); }; 25 | int Flags(void) const { return(m_flags); }; 26 | void SetUnicode(const bool unicode); 27 | void SetCommon(const bool common); 28 | //--- general methods for working with files 29 | int Open(const string file_name,int open_flags,const short delimiter='\t'); 30 | void Close(void); 31 | void Delete(void); 32 | ulong Size(void); 33 | ulong Tell(void); 34 | void Seek(const long offset,const ENUM_FILE_POSITION origin); 35 | void Flush(void); 36 | bool IsEnding(void); 37 | bool IsLineEnding(void); 38 | //--- general methods for working with files 39 | void Delete(const string file_name,const int common_flag=0); 40 | bool IsExist(const string file_name,const int common_flag=0); 41 | bool Copy(const string src_name,const int common_flag,const string dst_name,const int mode_flags); 42 | bool Move(const string src_name,const int common_flag,const string dst_name,const int mode_flags); 43 | //--- general methods of working with folders 44 | bool FolderCreate(const string folder_name); 45 | bool FolderDelete(const string folder_name); 46 | bool FolderClean(const string folder_name); 47 | //--- general methods of finding files 48 | long FileFindFirst(const string file_filter,string &returned_filename); 49 | bool FileFindNext(const long search_handle,string &returned_filename); 50 | void FileFindClose(const long search_handle); 51 | }; 52 | //+------------------------------------------------------------------+ 53 | //| Constructor | 54 | //+------------------------------------------------------------------+ 55 | CFile::CFile(void) : m_handle(INVALID_HANDLE), 56 | m_name(""), 57 | m_flags(FILE_ANSI) 58 | { 59 | } 60 | //+------------------------------------------------------------------+ 61 | //| Destructor | 62 | //+------------------------------------------------------------------+ 63 | CFile::~CFile(void) 64 | { 65 | //--- check handle 66 | if(m_handle!=INVALID_HANDLE) 67 | Close(); 68 | } 69 | //+------------------------------------------------------------------+ 70 | //| Set the FILE_UNICODE flag | 71 | //+------------------------------------------------------------------+ 72 | void CFile::SetUnicode(const bool unicode) 73 | { 74 | //--- check handle 75 | if(m_handle==INVALID_HANDLE) 76 | { 77 | if(unicode) 78 | m_flags|=FILE_UNICODE; 79 | else 80 | m_flags&=~FILE_UNICODE; 81 | } 82 | } 83 | //+------------------------------------------------------------------+ 84 | //| Set the "Common Folder" flag | 85 | //+------------------------------------------------------------------+ 86 | void CFile::SetCommon(const bool common) 87 | { 88 | //--- check handle 89 | if(m_handle==INVALID_HANDLE) 90 | { 91 | if(common) 92 | m_flags|=FILE_COMMON; 93 | else 94 | m_flags&=~FILE_COMMON; 95 | } 96 | } 97 | //+------------------------------------------------------------------+ 98 | //| Open the file | 99 | //+------------------------------------------------------------------+ 100 | int CFile::Open(const string file_name,int open_flags,const short delimiter) 101 | { 102 | //--- check handle 103 | if(m_handle!=INVALID_HANDLE) 104 | Close(); 105 | //--- action 106 | if((open_flags &(FILE_BIN|FILE_CSV))==0) 107 | open_flags|=FILE_TXT; 108 | //--- open 109 | m_handle=FileOpen(file_name,open_flags|m_flags,delimiter); 110 | if(m_handle!=INVALID_HANDLE) 111 | { 112 | //--- store options of the opened file 113 | m_flags|=open_flags; 114 | m_name=file_name; 115 | } 116 | //--- result 117 | return(m_handle); 118 | } 119 | //+------------------------------------------------------------------+ 120 | //| Close the file | 121 | //+------------------------------------------------------------------+ 122 | void CFile::Close(void) 123 | { 124 | //--- check handle 125 | if(m_handle!=INVALID_HANDLE) 126 | { 127 | //--- closing the file and resetting all the variables to the initial state 128 | FileClose(m_handle); 129 | m_handle=INVALID_HANDLE; 130 | m_name=""; 131 | //--- reset all flags except the text 132 | m_flags&=FILE_ANSI|FILE_UNICODE; 133 | } 134 | } 135 | //+------------------------------------------------------------------+ 136 | //| Deleting an open file | 137 | //+------------------------------------------------------------------+ 138 | void CFile::Delete(void) 139 | { 140 | //--- check handle 141 | if(m_handle!=INVALID_HANDLE) 142 | { 143 | string file_name=m_name; 144 | int common_flag=m_flags&FILE_COMMON; 145 | //--- close before deleting 146 | Close(); 147 | //--- delete 148 | FileDelete(file_name,common_flag); 149 | } 150 | } 151 | //+------------------------------------------------------------------+ 152 | //| Get size of opened file | 153 | //+------------------------------------------------------------------+ 154 | ulong CFile::Size(void) 155 | { 156 | //--- check handle 157 | if(m_handle!=INVALID_HANDLE) 158 | return(FileSize(m_handle)); 159 | //--- failure 160 | return(0); 161 | } 162 | //+------------------------------------------------------------------+ 163 | //| Get current position of pointer in file | 164 | //+------------------------------------------------------------------+ 165 | ulong CFile::Tell(void) 166 | { 167 | //--- check handle 168 | if(m_handle!=INVALID_HANDLE) 169 | return(FileTell(m_handle)); 170 | //--- failure 171 | return(0); 172 | } 173 | //+------------------------------------------------------------------+ 174 | //| Set position of pointer in file | 175 | //+------------------------------------------------------------------+ 176 | void CFile::Seek(const long offset,const ENUM_FILE_POSITION origin) 177 | { 178 | //--- check handle 179 | if(m_handle!=INVALID_HANDLE) 180 | FileSeek(m_handle,offset,origin); 181 | } 182 | //+------------------------------------------------------------------+ 183 | //| Flush data from the file buffer of input-output to disk | 184 | //+------------------------------------------------------------------+ 185 | void CFile::Flush(void) 186 | { 187 | //--- check handle 188 | if(m_handle!=INVALID_HANDLE) 189 | FileFlush(m_handle); 190 | } 191 | //+------------------------------------------------------------------+ 192 | //| Detect the end of file | 193 | //+------------------------------------------------------------------+ 194 | bool CFile::IsEnding(void) 195 | { 196 | //--- check handle 197 | if(m_handle!=INVALID_HANDLE) 198 | return(FileIsEnding(m_handle)); 199 | //--- failure 200 | return(false); 201 | } 202 | //+------------------------------------------------------------------+ 203 | //| Detect the end of string | 204 | //+------------------------------------------------------------------+ 205 | bool CFile::IsLineEnding(void) 206 | { 207 | //--- checking 208 | if(m_handle!=INVALID_HANDLE) 209 | if((m_flags&FILE_BIN)==0) 210 | return(FileIsLineEnding(m_handle)); 211 | //--- failure 212 | return(false); 213 | } 214 | //+------------------------------------------------------------------+ 215 | //| Deleting a file | 216 | //+------------------------------------------------------------------+ 217 | void CFile::Delete(const string file_name,const int common_flag) 218 | { 219 | //--- checking 220 | if(file_name==m_name) 221 | { 222 | int flag=m_flags&FILE_COMMON; 223 | if(flag==common_flag) 224 | Close(); 225 | } 226 | //--- delete 227 | FileDelete(file_name,common_flag); 228 | } 229 | //+------------------------------------------------------------------+ 230 | //| Check if file exists | 231 | //+------------------------------------------------------------------+ 232 | bool CFile::IsExist(const string file_name,const int common_flag) 233 | { 234 | return(FileIsExist(file_name,common_flag)); 235 | } 236 | //+------------------------------------------------------------------+ 237 | //| Copying file | 238 | //+------------------------------------------------------------------+ 239 | bool CFile::Copy(const string src_name,const int common_flag,const string dst_name,const int mode_flags) 240 | { 241 | return(FileCopy(src_name,common_flag,dst_name,mode_flags)); 242 | } 243 | //+------------------------------------------------------------------+ 244 | //| Move/rename file | 245 | //+------------------------------------------------------------------+ 246 | bool CFile::Move(const string src_name,const int common_flag,const string dst_name,const int mode_flags) 247 | { 248 | return(FileMove(src_name,common_flag,dst_name,mode_flags)); 249 | } 250 | //+------------------------------------------------------------------+ 251 | //| Create folder | 252 | //+------------------------------------------------------------------+ 253 | bool CFile::FolderCreate(const string folder_name) 254 | { 255 | return(::FolderCreate(folder_name,m_flags)); 256 | } 257 | //+------------------------------------------------------------------+ 258 | //| Delete folder | 259 | //+------------------------------------------------------------------+ 260 | bool CFile::FolderDelete(const string folder_name) 261 | { 262 | return(::FolderDelete(folder_name,m_flags)); 263 | } 264 | //+------------------------------------------------------------------+ 265 | //| Clean folder | 266 | //+------------------------------------------------------------------+ 267 | bool CFile::FolderClean(const string folder_name) 268 | { 269 | return(::FolderClean(folder_name,m_flags)); 270 | } 271 | //+------------------------------------------------------------------+ 272 | //| Start search of files | 273 | //+------------------------------------------------------------------+ 274 | long CFile::FileFindFirst(const string file_filter,string &returned_filename) 275 | { 276 | return(::FileFindFirst(file_filter,returned_filename,m_flags)); 277 | } 278 | //+------------------------------------------------------------------+ 279 | //| Continue search of files | 280 | //+------------------------------------------------------------------+ 281 | bool CFile::FileFindNext(const long search_handle,string &returned_filename) 282 | { 283 | return(::FileFindNext(search_handle,returned_filename)); 284 | } 285 | //+------------------------------------------------------------------+ 286 | //| End search of files | 287 | //+------------------------------------------------------------------+ 288 | void CFile::FileFindClose(const long search_handle) 289 | { 290 | ::FileFindClose(search_handle); 291 | } 292 | //+------------------------------------------------------------------+ 293 | -------------------------------------------------------------------------------- /Include/Canvas/Charts/HistogramChart.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| HistogramChart.mqh | 3 | //| Copyright 2009-2017, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #include "ChartCanvas.mqh" 7 | #include 8 | //+------------------------------------------------------------------+ 9 | //| Class CHistogramChart | 10 | //| Usage: generates histogram chart | 11 | //+------------------------------------------------------------------+ 12 | class CHistogramChart : public CChartCanvas 13 | { 14 | private: 15 | //--- colors 16 | uint m_fill_brush[]; 17 | //--- adjusted parameters 18 | bool m_gradient; 19 | uint m_bar_gap; 20 | uint m_bar_min_size; 21 | uint m_bar_border; 22 | //--- data 23 | CArrayObj *m_values; 24 | 25 | public: 26 | CHistogramChart(void); 27 | ~CHistogramChart(void); 28 | //--- create 29 | virtual bool Create(const string name,const int width,const int height,ENUM_COLOR_FORMAT clrfmt=COLOR_FORMAT_ARGB_NORMALIZE); 30 | //--- adjusted parameters 31 | void Gradient(const bool flag=true) { m_gradient=flag; } 32 | void BarGap(const uint value) { m_bar_gap=value; } 33 | void BarMinSize(const uint value) { m_bar_min_size=value; } 34 | void BarBorder(const uint value) { m_bar_border=value; } 35 | //--- data 36 | bool SeriesAdd(const double &value[],const string descr="",const uint clr=0); 37 | bool SeriesInsert(const uint pos,const double &value[],const string descr="",const uint clr=0); 38 | bool SeriesUpdate(const uint pos,const double &value[],const string descr=NULL,const uint clr=0); 39 | bool SeriesDelete(const uint pos); 40 | bool ValueUpdate(const uint series,const uint pos,double value); 41 | 42 | protected: 43 | virtual void DrawData(const uint idx); 44 | void DrawBar(const int x,const int y,const int w,const int h,const uint clr); 45 | void GradientBrush(const int size,const uint fill_clr); 46 | }; 47 | //+------------------------------------------------------------------+ 48 | //| Constructor | 49 | //+------------------------------------------------------------------+ 50 | CHistogramChart::CHistogramChart(void) : m_gradient(true), 51 | m_bar_gap(3), 52 | m_bar_min_size(5), 53 | m_bar_border(0) 54 | { 55 | ShowFlags(FLAG_SHOW_LEGEND|FLAGS_SHOW_SCALES|FLAG_SHOW_GRID); 56 | } 57 | //+------------------------------------------------------------------+ 58 | //| Destructor | 59 | //+------------------------------------------------------------------+ 60 | CHistogramChart::~CHistogramChart(void) 61 | { 62 | if(ArraySize(m_fill_brush)!=0) 63 | ArrayFree(m_fill_brush); 64 | } 65 | //+------------------------------------------------------------------+ 66 | //| Create dynamic resource | 67 | //+------------------------------------------------------------------+ 68 | bool CHistogramChart::Create(const string name,const int width,const int height,ENUM_COLOR_FORMAT clrfmt) 69 | { 70 | //--- create object to store data 71 | if((m_values=new CArrayObj)==NULL) 72 | return(false); 73 | //--- pass responsibility for its destruction to the parent class 74 | m_data=m_values; 75 | //--- call method of parent class 76 | if(!CChartCanvas::Create(name,width,height,clrfmt)) 77 | return(false); 78 | //--- succeed 79 | return(true); 80 | } 81 | //+------------------------------------------------------------------+ 82 | //| Adds data series | 83 | //+------------------------------------------------------------------+ 84 | bool CHistogramChart::SeriesAdd(const double &value[],const string descr,const uint clr) 85 | { 86 | //--- check 87 | if(m_data_total==m_max_data) 88 | return(false); 89 | //--- add 90 | CArrayDouble *arr=new CArrayDouble; 91 | if(!m_values.Add(arr)) 92 | return(false); 93 | if(!arr.AssignArray(value)) 94 | return(false); 95 | if(!m_colors.Add((clr==0) ? GetDefaultColor(m_data_total) : clr)) 96 | return(false); 97 | if(!m_descriptors.Add(descr)) 98 | return(false); 99 | m_data_total++; 100 | //--- redraw 101 | Redraw(); 102 | //--- succeed 103 | return(true); 104 | } 105 | //+------------------------------------------------------------------+ 106 | //| Inserts data series | 107 | //+------------------------------------------------------------------+ 108 | bool CHistogramChart::SeriesInsert(const uint pos,const double &value[],const string descr,const uint clr) 109 | { 110 | //--- check 111 | if(m_data_total==m_max_data) 112 | return(false); 113 | if(pos>=m_data_total) 114 | return(false); 115 | //--- insert 116 | CArrayDouble *arr=new CArrayDouble; 117 | if(!m_values.Insert(arr,pos)) 118 | return(false); 119 | if(!arr.AssignArray(value)) 120 | return(false); 121 | if(!m_colors.Insert((clr==0) ? GetDefaultColor(m_data_total) : clr,pos)) 122 | return(false); 123 | if(!m_descriptors.Insert(descr,pos)) 124 | return(false); 125 | m_data_total++; 126 | //--- redraw 127 | Redraw(); 128 | //--- succeed 129 | return(true); 130 | } 131 | //+------------------------------------------------------------------+ 132 | //| Updates data series | 133 | //+------------------------------------------------------------------+ 134 | bool CHistogramChart::SeriesUpdate(const uint pos,const double &value[],const string descr,const uint clr) 135 | { 136 | //--- check 137 | if(pos>=m_data_total) 138 | return(false); 139 | CArrayDouble *data=m_values.At(pos); 140 | if(data==NULL) 141 | return(false); 142 | //--- update 143 | if(!data.AssignArray(value)) 144 | return(false); 145 | if(clr!=0 && !m_colors.Update(pos,clr)) 146 | return(false); 147 | if(descr!=NULL && !m_descriptors.Update(pos,descr)) 148 | return(false); 149 | //--- redraw 150 | Redraw(); 151 | //--- succeed 152 | return(true); 153 | } 154 | //+------------------------------------------------------------------+ 155 | //| Deletes data series | 156 | //+------------------------------------------------------------------+ 157 | bool CHistogramChart::SeriesDelete(const uint pos) 158 | { 159 | //--- check 160 | if(pos>=m_data_total && m_data_total!=0) 161 | return(false); 162 | //--- delete 163 | if(!m_values.Delete(pos)) 164 | return(false); 165 | m_data_total--; 166 | if(!m_colors.Delete(pos)) 167 | return(false); 168 | if(!m_descriptors.Delete(pos)) 169 | return(false); 170 | //--- redraw 171 | Redraw(); 172 | //--- succeed 173 | return(true); 174 | } 175 | //+------------------------------------------------------------------+ 176 | //| Updates element in data series | 177 | //+------------------------------------------------------------------+ 178 | bool CHistogramChart::ValueUpdate(const uint series,const uint pos,double value) 179 | { 180 | CArrayDouble *data=m_values.At(series); 181 | //--- check 182 | if(data==NULL) 183 | return(false); 184 | //--- update 185 | if(!data.Update(pos,value)) 186 | return(false); 187 | //--- redraw 188 | Redraw(); 189 | //--- succeed 190 | return(true); 191 | } 192 | //+------------------------------------------------------------------+ 193 | //| Draws histogram | 194 | //+------------------------------------------------------------------+ 195 | void CHistogramChart::DrawData(const uint idx) 196 | { 197 | double value=0.0; 198 | //--- check 199 | CArrayDouble *data=m_values.At(idx); 200 | if(data==NULL) 201 | return; 202 | int total=data.Total(); 203 | if(total==0 || (int)idx>=total) 204 | return; 205 | //--- calculate 206 | int x1=m_data_area.left; 207 | int x2=m_data_area.right; 208 | int dx=(x2-x1)/total; 209 | uint clr=m_colors[idx]; 210 | uint w=dx/m_data_total; 211 | if(w0) 239 | { 240 | y=(m_y_0-(int)(value*m_scale_y)); 241 | h=m_y_0-y; 242 | } 243 | else 244 | { 245 | y=m_y_0; 246 | h=-(int)(value*m_scale_y); 247 | } 248 | DrawBar(x,y,w,h,clr); 249 | //--- draw text of value 250 | if(IS_SHOW_VALUE) 251 | { 252 | string text =DoubleToString(value,2); 253 | int width=(int)(TextWidth(text)+w); 254 | if(value>0) 255 | { 256 | if(width>y-m_y_max) 257 | TextOut(x+w/2,y+w,text,m_color_text,TA_RIGHT|TA_VCENTER); 258 | else 259 | TextOut(x+w/2,y-w,text,m_color_text,TA_LEFT|TA_VCENTER); 260 | } 261 | else 262 | { 263 | if(width>m_y_min-y-h) 264 | TextOut(x+w/2,y+h-w,text,m_color_text,TA_LEFT|TA_VCENTER); 265 | else 266 | TextOut(x+w/2,y+h+w,text,m_color_text,TA_RIGHT|TA_VCENTER); 267 | } 268 | } 269 | } 270 | if(IS_SHOW_VALUE) 271 | FontSet(fontname,fontsize,fontflags,fontangle); 272 | } 273 | //+------------------------------------------------------------------+ 274 | //| Draws bar | 275 | //+------------------------------------------------------------------+ 276 | void CHistogramChart::DrawBar(const int x,const int y,const int w,const int h,const uint clr) 277 | { 278 | //--- draw bar 279 | if(!m_gradient || ArraySize(m_fill_brush)>1; 319 | if((r&1)==0) 320 | i1--; 321 | //--- calculate 322 | while(dy>=dx) 323 | { 324 | clr=fill_clr; 325 | dclr=GETRGB(XRGB((r-dy)*GETRGBR(clr)/r,(r-dy)*GETRGBG(clr)/r,(r-dy)*GETRGBB(clr)/r)); 326 | clr-=dclr; 327 | m_fill_brush[i1]=clr; 328 | m_fill_brush[i2]=clr; 329 | //--- 330 | if(f>=0) 331 | { 332 | dy--; 333 | dd_y+=2; 334 | f+=dd_y; 335 | } 336 | dx++; 337 | if(--i1<0) 338 | break; 339 | i2++; 340 | dd_x+=2; 341 | f+=dd_x; 342 | } 343 | } 344 | else 345 | ArrayFree(m_fill_brush); 346 | } 347 | //+------------------------------------------------------------------+ 348 | --------------------------------------------------------------------------------