新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1389

 
Vitaly Muzichenko:

问题:创建的面板大小为370,我如何在压缩图形时将其大小调整为200?

删除和重绘,唯一的问题是在面板内,如果它突然变得比要求的小,那么就会滚动。如果你能把宽度指定为一个百分比,那就不错了。

HZZ在chrome中发生了一些事情,我的网站在引擎中(在php中),窗口宽度百分比起作用,高度不希望是最小值,只有当明确指定为像素时,它才起作用,操作系统也不再采取高度的百分比,mosilla至今起作用。但在chrome中,你可以改变页面代码中的数值,一切都能正常工作)

 
Valeriy Yastremskiy:

重画有什么问题吗? 删除和重画,唯一的问题是在面板里面,如果它突然变得比要求的小。 然后滚动。如果你能把宽度指定为一个百分比,那也不是一件坏事。

...

这就是问题的关键,我想重画,但我没有找到方法,后来发现。

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

面板本身可以调整大小,但内容却不能,我怎样才能重新绘制?

全码,指标。

#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:

问题就在这里,我想重画,但我还没有找到方法,后来找到了。

面板本身可以调整大小,但内容却不能,我怎样才能重新绘制?

全码,指标。

我不是专家,但会做这样的事情

//+------------------------------------------------------------------+
//| 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:

我不是专家,但我会做这样的事情

这是一种不好的清除方法。

 
Vitaly Muzichenko:

这是一种不好的清除方法。

我们能不能把参数

ClientAreaHeight();

这里?

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

我们能否把参数

在这里?

你可以,但这并不能解决这个问题

 
Vitaly Muzichenko:

你可以,但这并不能解决问题

我在想......我会考虑的。
 

面板的大小被调整,但内容的大小没有改变,而且不是所有的内容都被显示。

#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);
}
//+------------------------------------------------------------------+

内容中有40个项目,只有在第一次创建对话框 时适合高度尺寸的项目才会被显示。

---

帮忙解决,谁能。

 
Vitaly Muzichenko:

面板的大小被调整,但内容的大小没有改变,不是所有的内容都被显示出来。

内容中有40个项目,只有在第一次创建对话框 时适合高度尺寸的项目才会被显示。

---

帮忙解决,谁能。

你是否想在不改变内容大小的情况下改变窗口的大小?而且不仅是尺寸,坐标也要根据窗口的大小重新计算。甚至元素字母的字体大小...

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

我想知道一件事,如何在盈利时关闭订单。 假设我开了4个订单,两个买入,一个在Eurica,一个在Chif上买入。 还有一个卖出/我设置代码Profit = 10。

我应该正确制定代码,使两个买盘在总利润上关闭,或两个股票在总利润上关闭。

原因: