//+------------------------------------------------------------------+ //| TFGUIDialog.mqh | //| Thorsten Fischer Copyright 2020 | //| https://mql5.tfsystem.de | //+------------------------------------------------------------------+ #property copyright "Thorsten Fischer Copyright 2020" #property link "https://mql5.tfsystem.de" #property version "1.00" #property strict //--- #include #include "..\..\TF-Dateien\TF-Class\TFCheckBox.mqh" #include "..\..\TF-Dateien\TF-Class\TFEdit.mqh" #include "..\..\TF-Dateien\TF-Class\TFButton.mqh" #include "..\..\TF-Dateien\TF-Class\TFLabel.mqh" #include "..\..\TF-Dateien\TF-Class\TFTrade.mqh" //+------------------------------------------------------------------+ //| defines | //+------------------------------------------------------------------+ //--- indents and gaps #define INDENT_LEFT (5) // indent from left (with allowance for border width) #define INDENT_TOP (5) // indent from top (with allowance for border width) #define INDENT_RIGHT (5) // indent from right (with allowance for border width) #define INDENT_BOTTOM (5) // indent from bottom (with allowance for border width) #define CONTROLS_GAP_X (5) // gap by X coordinate #define CONTROLS_GAP_Y (5) // gap by Y coordinate #define CONTROLS_GAP_LABEL_EDIT (45) // gap by X coordinate //--- for buttons #define BUTTON_WIDTH (100) // size by X coordinate #define BUTTON_HEIGHT (20) // size by Y coordinate //--- for the indication area #define LABEL_WIDTH (140) // size by X coordinate #define LABEL_HEIGHT (20) // size by Y coordinate //--- for the indication area #define EDIT_WIDTH (60) // size by X coordinate #define EDIT_HEIGHT (20) // size by Y coordinate //--- for checkbox #define CHECK_WIDTH (180) // size by x coordinate #define CHECK_HEIGHT (20) // size by Y coordinate //--- for group controls #define GROUP_CONTROLS_GAP_Y (0) // gap by Y coordinate #define GROUP_WIDTH (150) // size by X coordinate #define LIST_HEIGHT (179) // size by Y coordinate #define RADIO_HEIGHT (56) // size by Y coordinate #define GROUP_CHECK_HEIGHT (93) // size by Y coordinate //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CTFGUIDialog : public CAppDialog { private: CTFCheckBox m_check_autotrading; CTFLabel m_label_price; CTFEdit m_edit_price; CTFLabel m_label_sl; CTFEdit m_edit_sl; CTFLabel m_label_tp; CTFEdit m_edit_tp; CTFLabel m_label_lots; CTFEdit m_edit_lots; CTFButton m_button_long; CTFButton m_button_short; CTFCheckBox m_check_long; CTFCheckBox m_check_short; CTFButton m_button_trade_open; CTFButton m_button_trade_close; CTFCheckBox m_check_trade_signal; public: CTFGUIDialog(); ~CTFGUIDialog(); //--- virtual bool Init(void); virtual void DeInit(const int aReason=0); virtual bool Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2); virtual void Destroy(const int aReason=0); virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam); protected: bool CreateCheckAutoTrading(void); bool CreateLabelPrice(void); bool CreateEditPrice(void); bool CreateLabelSL(void); bool CreateEditSL(void); bool CreateLabelTP(void); bool CreateEditTP(void); bool CreateLabelLots(void); bool CreateEditLots(void); bool CreateCheckLong(void); bool CreateCheckShort(void); bool CreateButtonTradeOpen(void); bool CreateButtonTradeClose(void); bool CreateCheckTradingSignal(void); //--- handlers of the dependent controls events void OnChangeAutoTrading(void); void OnEndEditPrice(void); void OnEndEditSL(void); void OnEndEditTP(void); void OnEndEditLots(void); void OnChangeLong(void); void OnChangeShort(void); void OnClickButtonOpen(void); void OnClickButtonClose(void); void OnChangeTradingSignal(void); }; //+------------------------------------------------------------------+ //| Event Handling | //+------------------------------------------------------------------+ EVENT_MAP_BEGIN(CTFGUIDialog) ON_EVENT(ON_CHANGE, m_check_autotrading, OnChangeAutoTrading) ON_EVENT(ON_END_EDIT, m_edit_price, OnEndEditPrice) ON_EVENT(ON_END_EDIT, m_edit_sl, OnEndEditSL) ON_EVENT(ON_END_EDIT, m_edit_tp, OnEndEditTP) ON_EVENT(ON_END_EDIT, m_edit_lots, OnEndEditLots) ON_EVENT(ON_CHANGE, m_check_long, OnChangeLong) ON_EVENT(ON_CHANGE, m_check_short, OnChangeShort) ON_EVENT(ON_CLICK, m_button_trade_open, OnClickButtonOpen) ON_EVENT(ON_CLICK, m_button_trade_close, OnClickButtonClose) ON_EVENT(ON_CHANGE, m_check_trade_signal, OnChangeTradingSignal) EVENT_MAP_END(CAppDialog) //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CTFGUIDialog::CTFGUIDialog() { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CTFGUIDialog::~CTFGUIDialog() { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2) { //--- if(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2)) return(false); //--- create dependent controls if(!CreateCheckAutoTrading()) return(false); if(!CreateLabelPrice()) return(false); if(!CreateEditPrice()) return(false); if(!CreateLabelSL()) return(false); if(!CreateEditSL()) return(false); if(!CreateLabelTP()) return(false); if(!CreateEditTP()) return(false); if(!CreateLabelLots()) return(false); if(!CreateEditLots()) return(false); if(!CreateCheckLong()) return(false); if(!CreateCheckShort()) return(false); if(!CreateButtonTradeOpen()) return(false); if(!CreateButtonTradeClose()) return(false); if(!CreateCheckTradingSignal()) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CTFGUIDialog::Destroy(const int aReason=0) { //--- CAppDialog::Destroy(aReason); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateCheckAutoTrading(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP; int x2=x1+CHECK_WIDTH; int y2=y1+CHECK_HEIGHT; //--- create if(!m_check_autotrading.Create(m_chart_id, m_name+"CheckBoxAutoTrading", m_subwin, x1, y1, x2, y2)) return(false); if(!m_check_autotrading.Text("Auto Trading")) return(false); if(!m_check_autotrading.Color(clrBlue)) return(false); if(!Add(m_check_autotrading)) return(false); if(!m_check_autotrading.Checked(g_tftrade.IsAutoTrading())) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateLabelPrice(void) { //--- coordinates int x1=INDENT_LEFT+EDIT_WIDTH+CONTROLS_GAP_X; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y; int x2=x1+LABEL_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+LABEL_HEIGHT; //--- create if(!m_label_price.Create(m_chart_id, m_name+"LabelPrice", m_subwin, x1, y1, x2, y2)) return(false); if(!m_label_price.Color(clrBlue)) return(false); if(!m_label_price.Text("Price = "+(string)g_tftrade.GetPrice())) return(false); if(!Add(m_label_price)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateEditPrice(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y; int x2=x1+EDIT_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+EDIT_HEIGHT; //--- create if(!m_edit_price.Create(m_chart_id, m_name+"EditPrice", m_subwin, x1, y1, x2, y2)) return(false); if(!m_edit_price.Color(clrBlue)) return(false); if(!m_edit_price.Text((string)g_tftrade.GetPrice())) return(false); if(!Add(m_edit_price)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateLabelSL(void) { //--- coordinates int x1=INDENT_LEFT+EDIT_WIDTH+CONTROLS_GAP_X; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+LABEL_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+LABEL_HEIGHT; //--- create if(!m_label_sl.Create(m_chart_id, m_name+"LabelSL", m_subwin, x1, y1, x2, y2)) return(false); if(!m_label_sl.Color(clrBlue)) return(false); if(!m_label_sl.Text("Stop Loss = "+(string)g_tftrade.GetSL())) return(false); if(!Add(m_label_sl)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateEditSL(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+EDIT_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+EDIT_HEIGHT; //--- create if(!m_edit_sl.Create(m_chart_id, m_name+"EditSL", m_subwin, x1, y1, x2, y2)) return(false); if(!m_edit_sl.Color(clrBlue)) return(false); if(!m_edit_sl.Text((string)g_tftrade.GetSL())) return(false); if(!Add(m_edit_sl)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateLabelTP(void) { //--- coordinates int x1=INDENT_LEFT+EDIT_WIDTH+CONTROLS_GAP_X; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+LABEL_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+LABEL_HEIGHT; //--- create if(!m_label_tp.Create(m_chart_id, m_name+"LabelTP", m_subwin, x1, y1, x2, y2)) return(false); if(!m_label_tp.Color(clrBlue)) return(false); if(!m_label_tp.Text("Take Profit = "+(string)g_tftrade.GetTP())) return(false); if(!Add(m_label_tp)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateEditTP(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+EDIT_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+EDIT_HEIGHT; //--- create if(!m_edit_tp.Create(m_chart_id, m_name+"EditTP", m_subwin, x1, y1, x2, y2)) return(false); if(!m_edit_tp.Color(clrBlue)) return(false); if(!m_edit_tp.Text((string)g_tftrade.GetTP())) return(false); if(!Add(m_edit_tp)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateLabelLots(void) { //--- coordinates int x1=INDENT_LEFT+EDIT_WIDTH+CONTROLS_GAP_X; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+LABEL_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+LABEL_HEIGHT; //--- create if(!m_label_lots.Create(m_chart_id, m_name+"LabelLots", m_subwin, x1, y1, x2, y2)) return(false); if(!m_label_lots.Color(clrBlue)) return(false); if(!m_label_lots.Text("Lots = "+(string)g_tftrade.GetLots())) return(false); if(!Add(m_label_lots)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateEditLots(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+EDIT_WIDTH; //ClientAreaWidth()-INDENT_RIGHT; int y2=y1+EDIT_HEIGHT; //--- create if(!m_edit_lots.Create(m_chart_id, m_name+"EditLots", m_subwin, x1, y1, x2, y2)) return(false); if(!m_edit_lots.Color(clrBlue)) return(false); if(!m_edit_lots.Text((string)g_tftrade.GetLots())) return(false); if(!Add(m_edit_lots)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateCheckLong(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y; int x2=x1+CHECK_WIDTH; int y2=y1+CHECK_HEIGHT; //--- create if(!m_check_long.Create(m_chart_id, m_name+"CheckBoxLong", m_subwin, x1, y1, x2, y2)) return(false); if(!m_check_long.Text("Long Trade")) return(false); if(!m_check_long.Color(clrBlue)) return(false); if(!Add(m_check_long)) return(false); if(!m_check_long.Checked(g_tftrade.IsLong())) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateCheckShort(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y; int x2=x1+CHECK_WIDTH; int y2=y1+CHECK_HEIGHT; //--- create if(!m_check_short.Create(m_chart_id, m_name+"CheckBoxShort", m_subwin, x1, y1, x2, y2)) return(false); if(!m_check_short.Text("Short Trade")) return(false); if(!m_check_short.Color(clrBlue)) return(false); if(!Add(m_check_short)) return(false); if(!m_check_short.Checked(g_tftrade.IsShort())) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateButtonTradeOpen(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y; int x2=x1+BUTTON_WIDTH; int y2=y1+BUTTON_HEIGHT; //--- create if(!m_button_trade_open.Create(m_chart_id, m_name+"TradeButtonOpen", m_subwin, x1, y1, x2, y2)) return(false); if(!m_button_trade_open.Text("Trade Open")) return(false); if(!Add(m_button_trade_open)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateButtonTradeClose(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y +BUTTON_HEIGHT+CONTROLS_GAP_Y; int x2=x1+BUTTON_WIDTH; int y2=y1+BUTTON_HEIGHT; //--- create if(!m_button_trade_close.Create(m_chart_id, m_name+"TradeButtonClose", m_subwin, x1, y1, x2, y2)) return(false); if(!m_button_trade_close.Text("Trade Close")) return(false); if(!Add(m_button_trade_close)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CTFGUIDialog::CreateCheckTradingSignal(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +LABEL_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y +CHECK_HEIGHT+CONTROLS_GAP_Y +BUTTON_HEIGHT+CONTROLS_GAP_Y +BUTTON_HEIGHT+CONTROLS_GAP_Y; int x2=x1+CHECK_WIDTH; int y2=y1+CHECK_HEIGHT; //--- create if(!m_check_trade_signal.Create(m_chart_id, m_name+"CheckBoxTradingSignal", m_subwin, x1, y1, x2, y2)) return(false); if(!m_check_trade_signal.Text("Trading Singal")) return(false); if(!m_check_trade_signal.Color(clrBlue)) return(false); if(!Add(m_check_trade_signal)) return(false); if(!m_check_trade_signal.Checked(g_tftrade.IsTradeSignal())) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnChangeAutoTrading(void) { //--- g_tftrade.IsAutoTrading(m_check_autotrading.Checked()); if(g_tftrade.IsAutoTrading()) PrintLog("Auto Trading aktiviert"); else PrintLog("Auto Trading deaktiviert"); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnEndEditPrice(void) { //--- double aValue=StringToDouble(m_edit_price.Text()); if(aValue>=0) g_tftrade.GetPrice(aValue); else PrintLog("Price darf nicht kleiner als 0 sein."); CreateLabelPrice(); CreateEditPrice(); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnEndEditSL(void) { //--- double aValue=StringToDouble(m_edit_sl.Text()); if(aValue>=0) g_tftrade.GetSL(aValue); else PrintLog("Stop Loss darf nicht kleiner als 0 sein."); CreateLabelSL(); CreateEditSL(); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnEndEditTP(void) { //--- double aValue=StringToDouble(m_edit_tp.Text()); if(aValue>=0) g_tftrade.GetTP(aValue); else PrintLog("Take Profit darf nicht kleiner als 0 sein."); CreateLabelTP(); CreateEditTP(); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnEndEditLots(void) { //--- double aValue=StringToDouble(m_edit_lots.Text()); if(aValue>=0) g_tftrade.GetLots(aValue); else PrintLog("Lots darf nicht kleiner als 0 sein."); CreateLabelLots(); CreateEditLots(); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnChangeLong(void) { //--- g_tftrade.IsLong(m_check_long.Checked()); if(g_tftrade.IsLong()) PrintLog("Trade Long aktiviert"); else PrintLog("Trade Long deaktiviert"); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnChangeShort(void) { //--- g_tftrade.IsShort(m_check_short.Checked()); if(g_tftrade.IsShort()) PrintLog("Trade Short aktiviert"); else PrintLog("Trade Short deaktiviert"); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnClickButtonOpen(void) { //--- g_tftrade.IsTradeSignal(true); if(!g_tftrade.CheckOpenTrading()) PrintLog(__FUNCTION__+" CheckOpenTrading konnte nicht fehlerfrei ausgeführt werden."); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnClickButtonClose(void) { //--- g_tftrade.CheckCloseTrading(); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CTFGUIDialog::OnChangeTradingSignal(void) { //--- g_tftrade.IsTradeSignal(m_check_trade_signal.Checked()); if(g_tftrade.IsTradeSignal()) PrintLog("Trading Signal aktiviert"); else PrintLog("Trading Signal deaktiviert"); } //+------------------------------------------------------------------+