The dialog is automatically maximized when switching the graph, please help

 

Have a nice day. I use the Dialog object of the CAppDialog class in the indicator and I can minimize it by the minimize button, but when switching the instrument or changing the time frame, it is automatically maximized again.

I need it to stay minimized when switching instr. or TF. Does anyone know how to do this?

I am attaching the code. Thanks


//+------------------------------------------------------------------+
//|                                                      PanelBS.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <Controls/Dialog.mqh>

CAppDialog   Panel;

int Xpos = 0;
int Ypos = 16; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping  
   
   Panel.Create(0,"Panel",0,0,0,250,146);
   Panel.Shift(Xpos,Ypos);
   Panel.Run();
   Panel.Caption("Panel");
         
//---
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
  {
   Panel.Destroy(reason);                                 
  }
  
//+------------------------------------------------------------------+
//| 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)
  {
//---
   Panel.ChartEvent(id,lparam,dparam,sparam); 
   
  }
//+------------------------------------------------------------------+
 
Jan Naj: but when switching the instrument or changing the time frame, it is automatically maximized again.

I need it to stay minimized when switching instr. or TF. Does anyone know how to do this?

  1. When switching, OnDeinit is called, indicators are unloaded, a new chart is drawn, indicators are reloaded, and OnInit is called. Your code runs as if it has just been placed on a chart; it draws a new panel. Why does this surprise you?

  2. In OnDeinit, check the UninitializeReason and if it is REASON_CHARTCHANGE, remember the state (open or minimized) in a Global Variable. In OnInit after creating the pane, check again, read the GV, and minimize it when necessary.

 
William Roeder #:
  1. When switching, OnDeinit is called, indicators are unloaded, a new chart is drawn, indicators are reloaded, and OnInit is called. Your code runs as if it has just been placed on a chart; it draws a new panel. Why does this surprise you?

  2. In OnDeinit, check the UninitializeReason and if it is REASON_CHARTCHANGE, remember the state (open or minimized) in a Global Variable. In OnInit after creating the pane, check again, read the GV, and minimize it when necessary.

Thank you very much for the answer, I probably understand what you mean, but I don't know two things and I can't find it.

1. I know save only a variable of type double in the Global Variable, I don't know how to save the state of minimize/maximize of the object from CAppDialog, or maybe the position on chart.

2. I don't know how to find out the status of the Dialog, to be able use it in OnDeinit. I tried everything I could think of, but I can't figure it out.

Can you please direct me? I'm trying, but I can't mov.

Thank you