Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1389

 
Vitaly Muzichenko:

Question: a panel is created with a size of 370, how do I resize it to 200 when compressing the graph ?

and what's the problem with redrawing? delete and redraw, the only issue is inside the panel if it suddenly becomes smaller than required. and then the scrolls. If you can specify the width as a percentage, it would not be bad.

HZZ in chrome something has happened, my site in the engine (in php), the window width percentage works, height does not want to be the minimum, only when explicitly specified in pixels, it works, operating system, too, stopped taking the percentage height, the mosilla so far works. But in chrome, you can change the values in the code of the page, and everything works)

 
Valeriy Yastremskiy:

What's the problem with redrawing? delete and redraw, the only issue is inside the panel if it suddenly becomes smaller than required. and then the scrolls. If you can specify the width as a percentage, that wouldn't be a bad thing.

...

That's the point, I want to redraw it, but I haven't found a way to do it, and I found it later:

ExtDialog.Height(ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS)-50);

The panel itself resizes, but the content does not, how can I redraw it?

Full code, indicator:

#include <Controls\Dialog.mqh>
#include <Controls\ListView.mqh>

//+------------------------------------------------------------------+
//| Class CPanelDialog                                               |
//| Usage: main dialog of the SimplePanel application                |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
  {
private:
   CListView         m_list_view;                     // the list object
   
public:
                     CPanelDialog(void);
                    ~CPanelDialog(void);
   //--- create
   virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
   //--- chart event handler
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   virtual void      OnChangeListView(void);
protected:
   //--- create dependent controls
   bool              CreateListView(void);
   //--- internal event handlers
   virtual bool      OnResize(void);
   //--- handlers of the dependent controls events
  // void              OnChangeListView(void);
   bool              OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam);
  };
  
//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView)
ON_OTHER_EVENTS(OnDefault)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CPanelDialog::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(!CreateListView())
      return(false);
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Create the "ListView" element                                    |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateListView(void)
  {
//--- coordinates
   int x1=0;
   int y1=0;
   int x2=ClientAreaWidth();
   int y2=ClientAreaHeight();
//--- create
   if(!m_list_view.Create(m_chart_id,m_name+"ListView",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!Add(m_list_view))
      return(false);
   m_list_view.Alignment(WND_ALIGN_HEIGHT,0,0,0,0);
//--- fill out with strings
   for(int i=0;i<25;i++)
      if(!m_list_view.ItemAdd("Item "+IntegerToString(i)))
         return(false);

//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Handler of resizing                                              |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
  {
//--- call method of parent class
   if(!CAppDialog::OnResize()) return(false);

//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Event handler                                                    |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeListView(void)
  {
  
  }
//+------------------------------------------------------------------+
//| Rest events handler                                                    |
//+------------------------------------------------------------------+
bool CPanelDialog::OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam)
  {

//--- let's handle event by parent
   return(false);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                  SimplePanel.mq4 |
//|                   Copyright 2009-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2014, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property version   "1.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0


//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- create application dialog
   if(!ExtDialog.Create(0,"Spread",0,12,12,250,300))
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
      return(INIT_FAILED);
//--- ok
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy application dialog
   ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
//---

//--- 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);

   if(id==CHARTEVENT_CHART_CHANGE || (id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,"MinMax")>0)) {
      if(ExtDialog.Height()>40) {
         ExtDialog.Height(ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS)-50);
         ExtDialog.OnChangeListView();
      }
     // Print(ExtDialog.Height());
   }
}
//+------------------------------------------------------------------+
 
Vitaly Muzichenko:

That's the thing, I want to redraw it, but I haven't found a way to do it, and I found it later:

The panel itself resizes but the content does not, how do I redraw it?

Full code, indicator:

I'm no expert, but would do something like this

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

   if(id==CHARTEVENT_CHART_CHANGE || (id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,"MinMax")>0)) {
      if(ExtDialog.Height()>40) {
         ExtDialog.Destroy();
         ExtDialog.Create(0,"Spread",0,12,12,250,ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS)-50);
      }
   }
}
 
MakarFX:

I'm no expert, but I would do something like this

This is a bad approach with removal.

 
Vitaly Muzichenko:

This is a bad approach with removal.

Can we put the parameters

ClientAreaHeight();

here?

void CPanelDialog::OnChangeListView(void)
  {
  
  }
 
MakarFX:

Can we put the parameters

in here?

You can, but it doesn't solve the problem

 
Vitaly Muzichenko:

You can, but it doesn't solve the problem

I was wondering...I'll think about it.
 

The size of the panel changes, but the size of the content does not, and not all of the content is displayed:

#include <Controls\Dialog.mqh>
#include <Controls\ListView.mqh>

//+------------------------------------------------------------------+
//| Class CPanelDialog                                               |
//| Usage: main dialog of the SimplePanel application                |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
  {
public:
   CListView         m_list_view;                     // the list object
   
public:
                     CPanelDialog(void);
                    ~CPanelDialog(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);
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   virtual void      OnChangeListView(void);
   
protected:
   bool              CreateListView(void);
   virtual bool      OnResize(void);
   bool              OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam);
  };
  
//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView)
ON_OTHER_EVENTS(OnDefault)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CPanelDialog::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(!CreateListView())
      return(false);
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Create the "ListView" element                                    |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateListView(void)
  {
//--- coordinates
   int x1=0;
   int y1=0;
   int x2=ClientAreaWidth();
   int y2=ClientAreaHeight();
//--- create
   m_list_view.Create(0,m_name+"ListView",0,x1,y1,x2,y2);
   m_list_view1.ColorBackground(clrMistyRose);
   if(!Add(m_list_view))
      return(false);
   m_list_view.Alignment(WND_ALIGN_HEIGHT,0,0,0,0);
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Handler of resizing                                              |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
  {
//--- call method of parent class
   if(!CAppDialog::OnResize()) return(false);

//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Event handler                                                    |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeListView(void)
  {
   
  }
//+------------------------------------------------------------------+
//| Rest events handler                                                    |
//+------------------------------------------------------------------+
bool CPanelDialog::OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_CHART_CHANGE || (id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,"MinMax")>0)) {
      if(ExtDialog.Height()>40) {
        ExtDialog.Height((int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS)-50); // меняем размер окна
        m_list_view.Height(ExtDialog.Height()-40); // меняем размер содержимого - работает странно
      }
   }
//--- let's handle event by parent
   return(false);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property version "1.00"
#property strict

#property indicator_chart_window


//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- create application dialog
   if(!ExtDialog.Create(0,"Spread",0,12,12,250,300))
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
      return(INIT_FAILED);
//--- ok
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy application dialog
   ExtDialog.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[])
{
 //---
    ExtDialog.m_list_view.ItemsClear();
     for(int i=1;i<40;i++) {
      ExtDialog.m_list_view.ItemAdd("Num "+(string)i+", Item "+(string)ExtDialog.Height());
     // Print(i);
     }
   
//--- 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.OnEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+

There are 40 items in the content, only what fits in the height dimension when the dialog is first created is displayed.

---

Help with the solution, who can.

 
Vitaly Muzichenko:

The panel is resized, but the size of the content is not changed and not all of the content is displayed:

There are 40 items in the content, only what fits in the height dimension when the dialog is first created is displayed.

---

Help with the solution, who can.

Did you want to change the size of the window without changing the size of the content??? And not only the size, but the coordinates have to be recalculated depending on the size of the window. And even the font size of the element labels...

 
if(Tip==0 && AccountProfit()>=OrderProfit()*Profit + OrderSwap()>0)
              {
              fc=OrderClose(OrderTicket(),lot,Bid, 2);
              } 
              if (Tip==1 && AccountProfit()>=OrderProfit()*Profit + OrderSwap()>0)
              {
               fc=OrderClose(OrderTicket(),lot,Ask,2);
              }       

I would like to know one thing, how to close orders on a profit. Let's say I open 4 orders, two buy, one in Eurica and one buy on Chif. And also one Sell / I set the code Profit = 10;

I should correctly formulate the code so two buys closed on the total Profit or two shares closed on the total.

Reason: