Crash while using Controls\Dialog.mqh

 

Hello all

When i make an indicator using (Controls mqh files) to draw a table checkboxes and attach it on any chart, it works fine.

But when i try to change the TF or symbol, the chart closes suddenly.


Here i attached the indicator

Here i attached the indicator


And here i tried to change the Time frame

Any Solution, please...


Code file in attachments

//+------------------------------------------------------------------+
//|                          Advanced price action APA Indicator.mq4 |
//|                             Copyright 2021, Ahmed Farag (Th3Eng) |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
#property indicator_chart_window
#include <common.mqh>
#include <Controls\Dialog.mqh>
#include <Controls\checkbox.mqh>
//--- panel
CAppDialog           AppWindow;
CCheckBox            checkBox1;
CCheckBox            checkBox2;
CCheckBox            checkBox3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   int y=40;
   if(ChartGetInteger(0,CHART_SHOW_ONE_CLICK))
      y=120;
//---
   if(ObjectFind(0,"th3eng_box1")>-1)
      return(INIT_SUCCEEDED);
//---
   if(!AppWindow.Create(0,"APA panel",0,5,y,200,y+250))
      return(INIT_FAILED);
//--- color
   int total=AppWindow.ControlsTotal();
   CWndClient*myclient;
   for(int i=0; i<total; i++)
     {
      CWnd*obj=AppWindow.Control(i);
      string name=obj.Name();
      PrintFormat("%d is %s",i,name);
      //--- color
      if(StringFind(name,"Client")>0)
        {
         CWndClient *client=(CWndClient*)obj;
         client.ColorBackground(clrMidnightBlue);
         myclient=client;
         ChartRedraw();
        }
     }
//---
   if(! draw_box1("th3eng_box1",5,5,150,30,"Box 1",clrWhite,14))
      return(INIT_FAILED);
   if(! draw_box2("th3eng_box2",5,40,150,70,"Box 2",clrWhite,14))
      return(INIT_FAILED);
   if(! draw_box3("th3eng_box3",5,80,150,110,"Box 3",clrWhite,14))
      return(INIT_FAILED);
//--- run application
   AppWindow.Run();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Indicator deinitialization function                              |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(reason!=3 && reason!=5)
      AppWindow.Destroy();
//---
  }
//+------------------------------------------------------------------+
//| 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)
  {
//---
   AppWindow.ChartEvent(id,lparam,dparam,sparam);
//---
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool draw_box1(string name, int x1, int y1, int x2, int y2, string text, color _text_color, int _fontSize)
  {
   if(!checkBox1.Create(0,name,0,x1,y1,x2,y2,clrBlack,clrGray))
      return(false);
   if(!checkBox1.Text(text))
      return(false);
   if(!checkBox1.Color(_text_color))
      return(false);
   if(!AppWindow.Add(checkBox1))
      return(false);
   return true;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool draw_box2(string name, int x1, int y1, int x2, int y2, string text, color _text_color, int _fontSize)
  {
   if(!checkBox2.Create(0,name,0,x1,y1,x2,y2,clrBlack,clrGray))
      return(false);
   if(!checkBox2.Text(text))
      return(false);
   if(!checkBox2.Color(_text_color))
      return(false);
   if(!AppWindow.Add(checkBox2))
      return(false);
   return true;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool draw_box3(string name, int x1, int y1, int x2, int y2, string text, color _text_color, int _fontSize)
  {
   if(!checkBox3.Create(0,name,0,x1,y1,x2,y2,clrBlack,clrGray))
      return(false);
   if(!checkBox3.Text(text))
      return(false);
   if(!checkBox3.Color(_text_color))
      return(false);
   if(!AppWindow.Add(checkBox3))
      return(false);
   return true;
  }
Files:
test.mq4  6 kb
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.

OK, thanks

 
  1. Your code
       if(!checkBox1.Create(0,name,0,x1,y1,x2,y2,clrBlack,clrGray))
          return(false);
       if(!checkBox1.Text(text))
          return(false);
       if(!checkBox1.Color(_text_color))
          return(false);
       if(!AppWindow.Add(checkBox1))
          return(false);
       return true;
    Simplified
       return checkBox1.Create(0,name,0,x1,y1,x2,y2,clrBlack,clrGray)
           && checkBox1.Text(text)
           && checkBox1.Color(_text_color)
           && AppWindow.Add(checkBox1);
    

  2. Ahmed Farag: But when i try to change the TF or symbol, the chart closes suddenly.

    Did you look up what uninit reason 3 is? It is chart change. You see exactly what must happen.

 
My panel breakout, when i change timeframe.
My panel breakout, when i change timeframe.
  • 2015.09.30
  • www.mql5.com
Dear Guys, I simply coding show panel on my chart. but My panel breakout when I change timeframe...
 
Ahmed Farag:

Hello all

When i make an indicator using (Controls mqh files) to draw a table checkboxes and attach it on any chart, it works fine.

But when i try to change the TF or symbol, the chart closes suddenly.


Here i attached the indicator



And here i tried to change the Time frame

Any Solution, please...


Code file in attachments

void OnDeinit(const int reason)
  {
//---
   if(reason!=3 && reason!=5)
      AppWindow.Destroy();
//---
  }
void OnDeinit(const int reason)
  {
//---
   if(reason!=3 && reason!=5)
      AppWindow.Destroy(reason);
//---
  }


try out this modification

there are many bugs in using the supplied include files, this is one of them, 

Reason: