Discussion of article "How to create a graphical panel of any complexity level" - page 12

 
Vladimir Karputov #:

It is forbidden. The panel is linked to the chart.

Thank you very much. I see.

May I ask for one more question, please.

I want to create a panel to show some table like this






















But I only can find the control below, is that mean panel can't support to create the table, thank you.

CLabel

Control, based on "Text label" graphic object

CBmpButton

Control, based on "Bitmap label" graphic object

CButton

Control, based on "Button" graphic object

CEdit

Control, based on "Edit field" graphic object

CPanel

Control, based on "Rectangle label"

CPicture

Control, based on "Bitmap label"

Documentation on MQL5: Standard Library / Panels and Dialogs / CEdit
Documentation on MQL5: Standard Library / Panels and Dialogs / CEdit
  • www.mql5.com
CEdit - Panels and Dialogs - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Quan tum # :

Thank you very much. I see.

May I ask for one more question, please.

I want to create a panel to show some table like this






















But I only can find the control below, is that mean panel can't support to create the table, thank you.

CLabel

Control, based on "Text label" graphic object

CBmpButton

Control, based on "Bitmap label" graphic object

CButton

Control, based on "Button" graphic object

CEdit

Control, based on "Edit field" graphic object

CPanel

Control, based on "Rectangle label"

CPicture

Control, based on "Bitmap label"

You need to build the table yourself. Look for examples in Articles and CodeBase.

 
Vladimir Karputov #:

You need to build the table yourself. Look for examples in Articles and CodeBase.

Ok, thank you very much. I think so.

I will try to find them in Article and codebase.

Thanks again for your support. 

 
Like
 

I'm trying to create a vertical scroll bar without linking to the panel, just on the chart, but it doesn't work for some reason.

For example, with a checkbox, this code reacts to a mouse click. The tick appears and disappears.

#include <Controls\CheckBox.mqh>
CCheckBox Chbox;
//+------------------------------------------------------------------+
void OnInit()
{
  Chbox.Create(0, "MyCheckBox", 0, 20, 20, 100, 40);
  ChartRedraw();
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
  Chbox.OnEvent(id, lparam, dparam, sparam);
}
//+------------------------------------------------------------------+


But with a vertical scroll - no reaction to mouse clicks.

#include <Controls\Scrolls.mqh>
CScrollV Scroll;

void OnInit()
{
  Scroll.Create(0, "MyScrollV", 0, 20, 20, 40, 200);
  ChartRedraw();
}

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
  Scroll.OnEvent(id, lparam, dparam, sparam);
}
//+------------------------------------------------------------------+

Can you please tell me who knows how to make this combined element work on a chart?

 

Can you tell me how to call a dialogue box?
For example, I have created a panel where there is a button "Close all positions". When I click on this button, a "Are you sure?" box should pop up. Yes/No. How to implement this?

Currently inheriting from CAppDialog, I created a small form with Ok/Cancel buttons. When clicking on the Ok button, I added a line

gDialogForm.Destroy();
ChartRedraw();

But the dialogue form still remains on the screen.
How to fix?

 
Nextor dialogue box?
For example, I have created a panel where there is a button "Close all positions". When I click on this button, a "Are you sure?" box should pop up. Yes/No. How to implement it?

Currently inheriting from CAppDialog, I created a small form with Ok/Cancel buttons. When clicking on the "Ok" button, I added a line

But the dialogue form still remains on the screen.
How to fix it?

void OnChartEvent(const int id,         // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
                 )
{
  // Close All Account
  if(id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,"ClosePos",0)!=-1)) {
    int MB=MessageBox("Close All Positions\nAccount Profit= "+DoubleToString(AccountInfoDouble(ACCOUNT_PROFIT),2),
                      "Close All Positions?", MB_OKCANCEL|MB_ICONQUESTION);
    if(MB==1)
      ClosePosSortProfit("", -1, -1, clrGray);
  }
}
 
Nextor dialogue box?
For example, I have created a panel where there is a button "Close all positions". When I click on this button, a "Are you sure?" box should pop up. Yes/No. How to implement it?

Currently inheriting from CAppDialog, I created a small form with Ok/Cancel buttons. When clicking on the "Ok" button, I added a line

But the dialogue form still remains on the screen.
How to fix it?

Maybe this comment will help
 
Nextor dialogue box?
For example, I have created a panel where there is a button "Close all positions". When I click on this button, a "Are you sure?" box should pop up. Yes/No. How to implement it?

Currently inheriting from CAppDialog, I created a small form with Ok/Cancel buttons. When clicking on the "Ok" button, I added a line

But the dialogue form still remains on the screen.
How to fix it?

Take the Close On Chart Panel example and insert a 'MessageBox' call into the click handlers.

In the 'Close On Chart Panel Dialog.mqh' file, make these changes:

//+------------------------------------------------------------------+
//| Event handler|
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton1(void)
  {
   int answer=MessageBox("Close all Sell?","Close all Sell",MB_OKCANCEL|MB_ICONQUESTION);
   if(answer==IDOK)
     {
      Print(__FUNCTION__);
      m_trading_engine.ClosePositions(POSITION_TYPE_SELL);
     }
  }
//+------------------------------------------------------------------+
//| Event handler|
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton2(void)
  {
   int answer=MessageBox("Close all Buy?","Close all Buy",MB_OKCANCEL|MB_ICONQUESTION);
   if(answer==IDOK)
     {
      Print(__FUNCTION__);
      m_trading_engine.ClosePositions(POSITION_TYPE_BUY);
     }
  }
//+------------------------------------------------------------------+
//| Event handler|
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton3(void)
  {
   int answer=MessageBox("Close all Profit?","Close all Profit",MB_OKCANCEL|MB_ICONQUESTION);
   if(answer==IDOK)
     {
      Print(__FUNCTION__);
      m_trading_engine.CloseProfitPositions();
     }
  }
//+------------------------------------------------------------------+
//| Event handler|
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton4(void)
  {
   int answer=MessageBox("Close all Loss?","Close all Loss",MB_OKCANCEL|MB_ICONQUESTION);
   if(answer==IDOK)
     {
      Print(__FUNCTION__);
      m_trading_engine.CloseLossPositions();
     }
  }


Result:


Close On Chart Panel
Close On Chart Panel
  • www.mql5.com
Советник-утилита. Панель на базе класса CDialog. Кнопки на базе класса СButton. Четыре кнопки для закрытия BUY, SELL, всех прибыльных, всех убыточных. Работа по текущему символу
 

Hi thanks for your amazing tutorial 

I'm trying to make my own , in my panel by click on one button the other one should be disable and hide , it will be hide when i click in the area of hidden button it still work 

I put my codes here if you could help me that will be great

Indicator:

//+------------------------------------------------------------------+
//|                                             Indicator_Q_Test.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#include  <WinUser32.mqh>
#include "PanelDialog_Q.mqh"
CPanelDialogQ ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   if(!ExtDialog.CreateQ(0,"Question",0,100,100,400,230,"This the test Question?"))
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
      return(INIT_FAILED);
 
      

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
      ExtDialog.ChartEvent(id,lparam,dparam,sparam);

  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   ExtDialog.Destroy(reason);


  }

Class:

//+------------------------------------------------------------------+
//|                                                  PanelDialog.mqh |
//|                   Copyright 2009-2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
#include <Controls\Edit.mqh>
#include <Controls\ListView.mqh>
#include <Controls\ComboBox.mqh>
#include <Controls\SpinEdit.mqh>
#include <Controls\RadioGroup.mqh>
#include <Controls\CheckGroup.mqh>
#include <Controls\Label.mqh>
#include <Controls\Scrolls.mqh>
//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
//--- indents and gaps
#define INDENT_LEFT_ScrollQ                         (11)      // indent from left (with allowance for border width)(for Scroll Bar Only)
#define INDENT_LEFTQ                         (11)      // indent from left (with allowance for border width)
#define INDENT_TOPQ                          (11)      // indent from top (with allowance for border width)
#define INDENT_RIGHTQ                        (11)      // indent from right (with allowance for border width)
#define INDENT_BOTTOMQ                       (11)      // indent from bottom (with allowance for border width)
#define CONTROLS_GAP_XQ                      (80)      // gap by X coordinate
#define CONTROLS_GAP_YQ                      (40)      // gap by Y coordinate
//--- for buttons
#define BUTTON_WIDTHQ                        (60)     // size by X coordinate
#define BUTTON_HEIGHTQ                       (20)      // size by Y coordinate
//--- for the indication area

#define EDIT_HEIGHTQ                         (20)      // size by Y coordinate
#define GROUP_WIDTHQ                         (150)     // size by X coordinate
#define LIST_HEIGHTQ                         (379)     // size by Y coordinate
#define RADIO_HEIGHTQ                        (56)      // size by Y coordinate
#define CHECK_HEIGHTQ                        (93)      // size by Y coordinate
//+------------------------------------------------------------------+
//| Class CPanelDialog                                               |
//| Usage: main dialog of the SimplePanel application                |
//+------------------------------------------------------------------+
class CPanelDialogQ : public CAppDialog
  {
private:

   CLabel            m_Label_Q_text;


   CButton           m_button_Yes;
   CButton           m_button_No;




   //****************************************************


public:
                     CPanelDialogQ(void);
                    ~CPanelDialogQ(void);
   //--- create
   virtual bool      CreateQ(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2,string QText);
   //--- chart event handler
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);

protected:

   //--- create dependent controls

   bool              CreateLabel_Q_text(string QT);

   bool              CreateButton_Yes(void);
   bool              CreateButton_No(void);


   void              OnClick_button_Yes(void);
   void              OnClick_button_No(void);


  };
//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialogQ)

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
ON_EVENT(ON_CLICK,m_button_Yes,OnClick_button_Yes)
ON_EVENT(ON_CLICK,m_button_No,OnClick_button_No)

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialogQ::CPanelDialogQ(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialogQ::~CPanelDialogQ(void)
  {
  }
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateQ(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2,string QText)
  {
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);
//--- create dependent controls

   if(!CreateLabel_Q_text(QText))
      return(false);
   if(!CreateButton_Yes())
      return(false);
   if(!CreateButton_No())
      return(false);

//--- succeed
   return(true);
  }


//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateLabel_Q_text(string QT)
  {
//--- coordinates
   int x1=INDENT_LEFTQ;
   int y1=INDENT_TOPQ;
   int x2=ClientAreaWidth()-(INDENT_RIGHTQ+BUTTON_WIDTHQ+CONTROLS_GAP_XQ);
   int y2=y1+EDIT_HEIGHTQ;

//--- create
   if(!m_Label_Q_text.Create(m_chart_id,"QT",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_Label_Q_text.Text(QT))
      return(false);
   if(!m_Label_Q_text.FontSize(12))
      return(false);
   if(!m_Label_Q_text.Color(clrBlack))
      return(false);
   if(!m_Label_Q_text.ColorBorder(clrBlack))
      return(false);
   if(!m_Label_Q_text.ColorBackground(clrBlack))
      return(false);
// if(!m_edit.ReadOnly(true))
//    return(false);
   if(!Add(m_Label_Q_text))
      return(false);

   m_Label_Q_text.Alignment(WND_ALIGN_WIDTH,INDENT_LEFTQ,0,INDENT_RIGHTQ+BUTTON_WIDTHQ+CONTROLS_GAP_XQ,0);
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateButton_Yes(void)
  {
//--- coordinates
   int x1=INDENT_LEFTQ;
   int y1=INDENT_TOPQ+CONTROLS_GAP_YQ;
   int x2=x1+BUTTON_WIDTHQ;
   int y2=y1+BUTTON_HEIGHTQ;
//--- create
   if(!m_button_Yes.Create(m_chart_id,m_name+"Yes",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button_Yes.Text("Yes"))
      return(false);
   if(!Add(m_button_Yes))
      return(false);
   m_button_Yes.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHTQ+CONTROLS_GAP_XQ*2,0);
//--- succeed
   return(true);
  }





//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateButton_No(void)
  {
//--- coordinates
   int x1=INDENT_LEFTQ+CONTROLS_GAP_XQ;
   int y1=INDENT_TOPQ+CONTROLS_GAP_YQ;
   int x2=x1+BUTTON_WIDTHQ;
   int y2=y1+BUTTON_HEIGHTQ;
//--- create
   if(!m_button_No.Create(m_chart_id,m_name+"NO",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button_No.Text("NO"))
      return(false);
   if(!Add(m_button_No))
      return(false);
   m_button_No.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHTQ+CONTROLS_GAP_XQ*1,0);
//--- succeed
   return(true);
  }

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void CPanelDialogQ::OnClick_button_Yes(void)
  {

   Print("OnClick_button_Yes", "Last Error: ",GetLastError());

  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void CPanelDialogQ::OnClick_button_No(void)
  {

   Print("OnClick_button_No", "Last Error: ",GetLastError());

m_button_Yes.Hide();
m_button_Yes.Disable();
m_button_Yes.Deactivate();

  }
//+------------------------------------------------------------------+