CAppDialog create problem when the timeframe change ( from an Example of Metaquotes) - page 2

 
Marcin Madrzak:

This is a bug in standard library in file Dialog.mqh. Fixed in MT5 btw. Add a line to that file as follows:

Thanks Marcin - honest_knave mentioned that above already and I changed that already here but this hasn't made any difference.

 
Jagg:

Thanks Marcin - honest_knave mentioned that above already and I changed that already here but this hasn't made any difference.

Hello, use the first method mentioned in this post:

https://www.mql5.com/en/forum/151390#comment_8956172

CAppDialog in Expert Advisors - terminal freezing after closing
CAppDialog in Expert Advisors - terminal freezing after closing
  • 2014.05.01
  • www.mql5.com
Hello, I tried to use new panel/controls interface in MetaTrader. I took SimplePanel.mq4+PanelDialog...
 

Hi all

I had the same issue, changed the line in the source code of CDialog but nothing worked.

My workaround was :

  • Check for a chart event change
  • Destroy the panel and recreate it
  • Continue handling event and other events

This worked perfectly. I had to write a separate CreatePanel function that was called from the event handler of the indicator and from the OnInit of the indicator.

Hope it helps.

 
Dennis:

Hi! 

The following code is an example of metaquotes. 



If this code implemented to MQL5 and change the timeframe it is working fine like the picture below :



but if this code implemented to MQL4 and change the timeframe it doesn't work properly :


It seem to create extra objects every time i change the timeframe 


Any idea to solve that problem ?


Thanks!


Hello everyone, I found the solution to the error of the function (CAppDialog :: Destroy) of the include file (Dialog.mqh).


The solution I found was to create a global variable of type integer to create a condition in the (OnInit ()) function. I also had to create a condition in the OnDeinit () function. Below I show you the code so that you have a better idea, I hope it helps you.

//+------------------------------------------------------------------+
//|                                                     Panel.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>


//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+

#define INDENT_LEFT                         (11)    
#define INDENT_TOP                          (11)   
#define CONTROLS_GAP_X                      (5)      

#define BUTTON_WIDTH                        (100) 
#define BUTTON_HEIGHT                       (20)     


int Error;
//+------------------------------------------------------------------+
//| Class CControlsDialog                                            |
//| Usage: main dialog of the Controls application                   |
//+------------------------------------------------------------------+
class CAppWindowCorrectMinimization : public CAppDialog
  {
private:
   CButton           m_button1;                     
  
  
public:
                     CAppWindowCorrectMinimization(void);
                    ~CAppWindowCorrectMinimization(void);
 
virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);

protected:
 
bool              CreateButton1(void);
 

  };
  
  
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CAppWindowCorrectMinimization::CAppWindowCorrectMinimization(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CAppWindowCorrectMinimization::~CAppWindowCorrectMinimization(void)
  {
  }
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CAppWindowCorrectMinimization::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(!CreateButton1())
      return(false);
   
//--- succeed
   return(true);
  }
  
  
  
//+------------------------------------------------------------------+
//| Global Variable                                                  |
//+------------------------------------------------------------------+
CAppWindowCorrectMinimization ExtDialog;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  
if(Error==3)return(0);
//--- create application dialog
   if(!ExtDialog.Create(0,"AppWindowClass with Two Buttons",0,50,50,390,200))
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
   return(INIT_FAILED);
    
//--- succeed
   return(INIT_SUCCEEDED);

  }
  
  


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
Error=reason;
if(reason!=3)ExtDialog.Destroy(reason);
  }
//+------------------------------------------------------------------+
//| Expert chart event function                                      |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // event ID  
                  const long& lparam,   // event parameter of the long type
                  const double& dparam, // event parameter of the double type
                  const string& sparam) // event parameter of the string type
  {
   ExtDialog.ChartEvent(id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
//| Create the "Button1" button                                      |
//+------------------------------------------------------------------+
bool CAppWindowCorrectMinimization::CreateButton1(void)
  {
//--- coordinates
   int x1=INDENT_LEFT;        
   int y1=INDENT_TOP;        
   int x2=x1+BUTTON_WIDTH;   
   int y2=y1+BUTTON_HEIGHT; 
//--- create
   if(!m_button1.Create(0,"Button1",0,x1,y1,x2,y2))
      return(false);
   if(!m_button1.Text("Button1"))
      return(false);
   if(!Add(m_button1))
      return(false);
//--- succeed
   return(true);
  }

        



 

thanks to all trial to resolve this issue in mql4

I have the same problem and trying to sort it out.

but after reading and scrutinize all your posts, and have some trials, 

I found it now much easier at ondeinit, to write the reason is (wrong value) as you can find in picture 




good luck to all

 
Mohamed Hassan Mohamed Hassan Alsherbiny:

thanks to all trial to resolve this issue in mql4

I have the same problem and trying to sort it out.

but after reading and scrutinize all your posts, and have some trials, 

I found it now much easier at ondeinit, to write the reason is (wrong value) as you can find in picture 




good luck to all

WOW...  that worked great.. 

I too went through all the explanations and found that just adding the deinit worked perfectly for me.

It even fixed my "cannot set millisecond timer(100)"


Thanks

 
Mohamed Hassan Mohamed Hassan Alsherbiny #:

thanks to all trial to resolve this issue in mql4

I have the same problem and trying to sort it out.

but after reading and scrutinize all your posts, and have some trials, 

I found it now much easier at ondeinit, to write the reason is (wrong value) as you can find in picture 




good luck to all

Great thanks it's work ... 

 
Most of these solutions fixed the problem when loading the EA. But the issue still persists when I save that EA as a template and then try to load it on a different chart. The table is still bugged. Does anyone know a workaround? Thanks
 

Found the fix on this thread:

https://www.mql5.com/en/forum/371563

Add this to your OnInit() function:

   int  ret=ObjectsDeleteAll(0);
SOME! Dialog Elements are not visible
SOME! Dialog Elements are not visible
  • 2021.06.18
  • www.mql5.com
Hello, i have a strange problem and just want to post it, first, without code. I have CAppDialog derived Dialog with some CLabels, CButtons etc...