Experts/TM-C-100/TFGUIDialog.mqh
super.admin da793cc2e1 convert
2025-05-30 14:54:10 +02:00

550 lines
42 KiB
MQL5

//+------------------------------------------------------------------+
//| 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 "..\..\TF-Dateien\TF-Class\TFAppDialog.mqh"
#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 CTFAppDialog
{
private:
//---
CTFLabel m_label_strategie_c;
CTFEdit m_edit_strategie_c;
CTFLabel m_label_strategie_tp;
CTFEdit m_edit_strategie_tp;
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_trade_long;
CTFButton m_button_trade_short;
public:
CTFGUIDialog();
~CTFGUIDialog();
//---
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 CreateLabelStrategieC(void);
bool CreateEditStrategieC(void);
bool CreateLabelStrategieTP(void);
bool CreateEditStrategieTP(void);
bool CreateLabelSL(void);
bool CreateEditSL(void);
bool CreateLabelTP(void);
bool CreateEditTP(void);
bool CreateLabelLots(void);
bool CreateEditLots(void);
bool CreateButtonTradeLong(void);
bool CreateButtonTradeShort(void);
//--- handlers of the dependent controls events
void OnEndEditStrategieC(void);
void OnEndEditStrategieTP(void);
void OnEndEditSL(void);
void OnEndEditTP(void);
void OnEndEditLots(void);
void OnChangeLong(void);
void OnChangeShort(void);
void OnClickButtonLong(void);
void OnClickButtonShort(void);
};
//+------------------------------------------------------------------+
//| Event Handling |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CTFGUIDialog)
ON_EVENT(ON_END_EDIT, m_edit_strategie_c, OnEndEditStrategieC)
ON_EVENT(ON_END_EDIT, m_edit_strategie_c, OnEndEditStrategieTP)
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_CLICK, m_button_trade_long, OnClickButtonLong)
ON_EVENT(ON_CLICK, m_button_trade_short, OnClickButtonShort)
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(!CTFAppDialog::Create(chart, name, subwin, x1, y1, x2, y2))
return(false);
//--- create dependent controls
//if(!CreateLabelStrategieC())
// return(false);
//if(!CreateEditStrategieC())
// return(false);
//if(!CreateLabelStrategieTP())
// return(false);
//if(!CreateEditStrategieTP())
// 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(!CreateButtonTradeLong())
// return(false);
//if(!CreateButtonTradeShort())
// return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CTFGUIDialog::Destroy(const int aReason=0)
{
//---
CAppDialog::Destroy(aReason);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateLabelStrategieC(void)
{
//--- coordinates
int x1=INDENT_LEFT+EDIT_WIDTH+CONTROLS_GAP_X;
int y1=INDENT_TOP ;
int x2=x1+LABEL_WIDTH;
int y2=y1+LABEL_HEIGHT;
//--- create
if(!m_label_strategie_c.Create(m_chart_id, m_name+"LabelStrategieC", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_label_strategie_c.Color(clrBlue))
return(false);
if(!m_label_strategie_c.Text("Strategie Close = "+(string)g_tftrade.StrategieC()))
return(false);
if(!Add(m_label_strategie_c))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateEditStrategieC(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP ;
int x2=x1+EDIT_WIDTH;
int y2=y1+EDIT_HEIGHT;
//--- create
if(!m_edit_strategie_c.Create(m_chart_id, m_name+"EditStrategieC", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_edit_strategie_c.Color(clrBlue))
return(false);
if(!m_edit_strategie_c.Text((string)g_tftrade.StrategieC()))
return(false);
if(!Add(m_edit_strategie_c))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateLabelStrategieTP(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;
int y2=y1+LABEL_HEIGHT;
//--- create
if(!m_label_strategie_c.Create(m_chart_id, m_name+"LabelStrategieTP", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_label_strategie_c.Color(clrBlue))
return(false);
if(!m_label_strategie_c.Text("Strategie TP = "+(string)g_tftrade.StrategieTP()))
return(false);
if(!Add(m_label_strategie_c))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateEditStrategieTP(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_strategie_c.Create(m_chart_id, m_name+"EditStrategieTP", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_edit_strategie_c.Color(clrBlue))
return(false);
if(!m_edit_strategie_c.Text((string)g_tftrade.StrategieTP()))
return(false);
if(!Add(m_edit_strategie_c))
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;
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.SL()))
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;
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.SL()))
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;
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.TP()))
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;
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.TP()))
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;
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.Lots()))
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;
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.Lots()))
return(false);
if(!Add(m_edit_lots))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateButtonTradeLong(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP
+LABEL_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+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button_trade_long.Create(m_chart_id, m_name+"TradeButtonLong", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_button_trade_long.Text("Trade Long"))
return(false);
if(!Add(m_button_trade_long))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateButtonTradeShort(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP
+LABEL_HEIGHT+CONTROLS_GAP_Y
+LABEL_HEIGHT+CONTROLS_GAP_Y
+LABEL_HEIGHT+CONTROLS_GAP_Y
+LABEL_HEIGHT+CONTROLS_GAP_Y
+LABEL_HEIGHT+CONTROLS_GAP_Y
+BUTTON_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button_trade_short.Create(m_chart_id, m_name+"TradeButtonShort", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_button_trade_short.Text("Trade Short"))
return(false);
if(!Add(m_button_trade_short))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditStrategieC(void)
{
//---
int aValue=(int)StringToInteger(m_edit_strategie_c.Text());
if(aValue>=0 && aValue<10)
g_tftrade.StrategieC(aValue);
else
PrintLog("Strategie Close darf nicht kleiner als 0 und größer als 9 sein. (0-9)");
CreateLabelStrategieC();
CreateEditStrategieC();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditStrategieTP(void)
{
//---
int aValue=(int)StringToInteger(m_edit_strategie_c.Text());
if(aValue>=0 && aValue<10)
g_tftrade.StrategieTP(aValue);
else
PrintLog("Strategie TP darf nicht kleiner als 0 und größer als 9 sein. (0-9)");
CreateLabelStrategieTP();
CreateEditStrategieTP();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditSL(void)
{
//---
double aValue=StringToDouble(m_edit_sl.Text());
if(aValue>=0)
g_tftrade.SL(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.TP(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.Lots(aValue);
else
PrintLog("Lots darf nicht kleiner als 0 sein.");
CreateLabelLots();
CreateEditLots();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnClickButtonLong(void)
{
//---
g_tftrade.IsTradeSignal(true);
g_tftrade.IsLong(true);
g_tftrade.IsShort(false);
if(!g_tftrade.CheckOpenTrading())
PrintLog(__FUNCTION__+" CheckOpenTrading konnte nicht fehlerfrei ausgeführt werden.");
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnClickButtonShort(void)
{
//---
g_tftrade.IsTradeSignal(true);
g_tftrade.IsLong(false);
g_tftrade.IsShort(true);
if(!g_tftrade.CheckOpenTrading())
PrintLog(__FUNCTION__+" CheckOpenTrading konnte nicht fehlerfrei ausgeführt werden.");
}
//+------------------------------------------------------------------+