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

606 lines
47 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_sl;
CTFEdit m_edit_strategie_c_sl;
CTFLabel m_label_strategie_c_tp;
CTFEdit m_edit_strategie_c_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;
CTFLabel m_label_magic_number;
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 CreateLabelStrategieCSL(void);
bool CreateEditStrategieCSL(void);
bool CreateLabelStrategieCTP(void);
bool CreateEditStrategieCTP(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);
bool CreateLabelMagicNumber(void);
//--- handlers of the dependent controls events
void OnEndEditStrategieCSL(void);
void OnEndEditStrategieCTP(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_sl, OnEndEditStrategieCSL)
ON_EVENT(ON_END_EDIT, m_edit_strategie_c_tp, OnEndEditStrategieCTP)
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(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2))
return(false);
//--- create dependent controls
if(!CreateLabelStrategieCSL())
return(false);
if(!CreateEditStrategieCSL())
return(false);
if(!CreateLabelStrategieCTP())
return(false);
if(!CreateEditStrategieCTP())
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);
if(!CreateLabelMagicNumber())
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CTFGUIDialog::Destroy(const int aReason=0)
{
//---
CAppDialog::Destroy(aReason);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateLabelStrategieCSL(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_sl.Create(m_chart_id, m_name+"LabelStrategieCSL", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_label_strategie_c_sl.Color(clrBlue))
return(false);
if(!m_label_strategie_c_sl.Text("Strategie Close SL = "+(string)g_tftrade.StrategieCSL()))
return(false);
if(!Add(m_label_strategie_c_sl))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateEditStrategieCSL(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_sl.Create(m_chart_id, m_name+"EditStrategieCSL", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_edit_strategie_c_sl.Color(clrBlue))
return(false);
if(!m_edit_strategie_c_sl.Text((string)g_tftrade.StrategieCSL()))
return(false);
if(!Add(m_edit_strategie_c_sl))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateLabelStrategieCTP(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_tp.Create(m_chart_id, m_name+"LabelStrategieCTP", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_label_strategie_c_tp.Color(clrBlue))
return(false);
if(!m_label_strategie_c_tp.Text("Strategie Close TP = "+(string)g_tftrade.StrategieCTP()))
return(false);
if(!Add(m_label_strategie_c_tp))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateEditStrategieCTP(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP +CHECK_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+EDIT_WIDTH;
int y2=y1+EDIT_HEIGHT;
//--- create
if(!m_edit_strategie_c_tp.Create(m_chart_id, m_name+"EditStrategieCTP", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_edit_strategie_c_tp.Color(clrBlue))
return(false);
if(!m_edit_strategie_c_tp.Text((string)g_tftrade.StrategieCTP()))
return(false);
if(!Add(m_edit_strategie_c_tp))
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CTFGUIDialog::CreateLabelMagicNumber(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
+BUTTON_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+LABEL_WIDTH;
int y2=y1+LABEL_HEIGHT;
//--- create
if(!m_label_magic_number.Create(m_chart_id, m_name+"LabelMagicNumber", m_subwin, x1, y1, x2, y2))
return(false);
if(!m_label_magic_number.Color(clrBlue))
return(false);
if(!m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber()))
return(false);
if(!Add(m_label_magic_number))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditStrategieCSL(void)
{
//---
int aValue=(int)StringToInteger(m_edit_strategie_c_sl.Text());
if(aValue>=0 && aValue<100)
g_tftrade.StrategieCSL(aValue);
else
PrintLogInfo("Strategie Close darf nicht kleiner als 0 und größer als 99 sein. (0-99)");
//---
m_label_strategie_c_sl.Text("Strategie Close SL = "+(string)g_tftrade.StrategieCSL());
m_edit_strategie_c_sl.Text((string)g_tftrade.StrategieCSL());
m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber());
//---
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditStrategieCTP(void)
{
//---
int aValue=(int)StringToInteger(m_edit_strategie_c_tp.Text());
if(aValue>=0 && aValue<100)
g_tftrade.StrategieCTP(aValue);
else
PrintLogInfo("Strategie Close TP darf nicht kleiner als 0 und größer als 99 sein. (0-99)");
//---
m_label_strategie_c_tp.Text("Strategie Close TP = "+(string)g_tftrade.StrategieCTP());
m_edit_strategie_c_tp.Text((string)g_tftrade.StrategieCTP());
m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber());
//---
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditSL(void)
{
//---
int aValue=(int)StringToInteger(m_edit_sl.Text());
if(aValue>=0)
g_tftrade.SL(aValue);
else
PrintLogInfo("Stop Loss darf nicht kleiner als 0 sein.");
//---
m_label_sl.Text("Stop Loss = "+(string)g_tftrade.SL());
m_edit_sl.Text((string)g_tftrade.SL());
//m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber());
//---
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditTP(void)
{
//---
int aValue=(int)StringToInteger(m_edit_tp.Text());
if(aValue>=0)
g_tftrade.TP(aValue);
else
PrintLogInfo("Take Profit darf nicht kleiner als 0 sein.");
//---
m_label_tp.Text("Take Profit = "+(string)g_tftrade.TP());
m_edit_tp.Text((string)g_tftrade.TP());
//m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber());
//---
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnEndEditLots(void)
{
//---
double aValue=StringToDouble(m_edit_lots.Text());
if(aValue>=0)
g_tftrade.Lots(aValue);
else
PrintLogInfo(__FUNCTION__+" Lots darf nicht kleiner als 0 sein.");
//---
m_label_lots.Text("Lots = "+(string)g_tftrade.Lots());
m_edit_lots.Text((string)g_tftrade.Lots());
//m_label_magic_number.Text("MN = "+(string)g_magicnumber.GetMagicNumber());
//---
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CTFGUIDialog::OnClickButtonLong(void)
{
//---
g_tftrade.IsTradeSignal(true);
g_tftrade.IsLong(true);
g_tftrade.IsShort(false);
g_tftrade.Price(0);
if(!g_tftrade.CheckOpenTrading())
PrintLogInfo(__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);
g_tftrade.Price(0);
if(!g_tftrade.CheckOpenTrading())
PrintLogInfo(__FUNCTION__+" CheckOpenTrading konnte nicht fehlerfrei ausgeführt werden.");
}
//+------------------------------------------------------------------+