Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1174

 
Alexey Viktorov:

The second and subsequent dimensions of an array cannot be dynamic. Therefore, as an array is declared, for example, int Mas[][7]; it must be taken by MyFun(int &Mas[][7])

Yes, it is.
Thanks. I didn't have the brains for it.
 

Hello programmers. Once again I'm asking for your help. There is a standard indicator from which I want to get a single value. I have connected the indicator and copied an array of its values into the buffer double buf_atr[] Printed to the log ArrayPrint(buf_atr) shows these values:

0.00032 0.00037 0.00039 0.00039 0.00041 0.00039 0.00037 0.00036 0.00034 0.00035 0.00035 0.00035 0.00034 0.00030

HOW DO I APPLY TO THE MASSIVE KEY WHICH HAS THE VALUE 0.00030? It turns out that this value is not on the current candle 0 and the previous is already formed 1

It seems to work, but how to access the cell array to further work with it I do not know ;(

input int InpPeriod=14;  // period
int handleIndicator; //указатель на индикатор


int OnInit()
{  
  
handleIndicator = iCustom(NULL,0,"Examples\\INDICATOR",InpPeriod);

   return(INIT_SUCCEEDED);
}



void OnTick()

{

int buf_size = 14;
double buf_atr[];

CopyBuffer(handleIndicator,0,0,buf_size,buf_atr);

ArrayPrint(buf_atr);

}
 
Kolya32:

Hello programmers. Once again I'm asking for your help. There is a standard indicator from which I want to get a single value. I have connected the indicator and copied an array of its values into the buffer double buf_atr[] Printed to the log ArrayPrint(buf_atr) shows these values:

0.00032 0.00037 0.00039 0.00039 0.00041 0.00039 0.00037 0.00036 0.00034 0.00035 0.00035 0.00035 0.00034 0.00030

HOW DO I APPLY TO THE MASSIVE KEY WHICH HAS THE VALUE 0.00030? It turns out that this value is not on the current candle 0 and the previous has already formed 1

It seems to work, but how to access the cell array to further work with it I do not know ;(

void OnTick()

{

int buf_size = 14;
double buf_atr[];

CopyBuffer(handleIndicator,0,0,buf_size,buf_atr);
Print( buf_atr[buf_size-1] ); // Массив начинается с нуля
ArrayPrint(buf_atr);

}
 
Vitaly Muzichenko:
void OnTick()

{

int buf_size = 14;
double buf_atr[];

CopyBuffer(handleIndicator,0,0,buf_size,buf_atr);
Print( buf_atr[buf_size-1] ); // Массив начинается с нуля
ArrayPrint(buf_atr);

}


IT WORKS YAY!!! I need to turn tobuf_atr[buf_size-1] I HAVE Tried EV ERYTHING. Many thanks to youVitaly Muzichenko.

 

Is mql styling mandatory, array reference ?

(
                                     double &value[],// Buffer of values
                                     double& clr[],                                 // Color buffer
                                     const bool asSeries,                           // Numbering flag as in time series
                                     const string label,                           // Series name
                                     const color& colors[],                        // Line colors )
 
CreatedCAppDialogPTR class - descendant of CAppDialog - advise how to properly override m_background, m_caption ... from CDialog class to access them from my class?
#property strict
#include <Controls\Dialog.mqh>

class CAppDialogPTR : public CAppDialog
{
private:
   int               m_deinit_reason;
public:
   CAppDialogPTR(void){};
   ~CAppDialogPTR(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);
};

bool CAppDialogPTR::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
   m_deinit_reason=WRONG_VALUE;
   bool res = CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2);
   return(res);
}

Dialog.mqh.

***
class CDialog : public CWndContainer
  {
private:
   //--- dependent controls
   CPanel            m_white_border;        // the "white border" object
   CPanel            m_background;          // the background object
   CEdit             m_caption;             // the window title object
   CBmpButton        m_button_close;        // the "Close" button object
   CWndClient        m_client_area;         // the client area object
***
 
Peter Vorobyev:
CreatedCAppDialogPTR class - descendant of CAppDialog - advise how to properly override m_background, m_caption ... from CDialog class to access them from my class?

Dialog.mqh.

You can't. These objects are locked from direct modification in your class, as indicated by the private keyword. You cannot work with them directly. Use methods of CDialog class which work with these fields.

 
Vasiliy Sokolov:

You can't. These objects are locked from direct modification in your class, as indicated by the private keyword. You cannot work with them directly. Use methods of your CDialog class that work with these fields.

Let's assume.

A created instance of theCAppDialogPTR classhas controls ( CWndContainerclass-> CWnd* Control(const int ind) const { return(dynamic_cast<CWnd *>(m_controls.At(ind)); }) through whichm_background, m_caption can be accessed

1) What is the syntax for accessing (referring to memory) the created object?

"CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2);"
 
Peter Vorobyev:

Suppose.

A created instance of theCAppDialogPTR classhas controls ( CWndContainerclass -> CWnd* Control(const int ind) const { return(dynamic_cast<CWnd *>(m_controls.At(ind)); } ) through whichm_background, m_caption can be accessed

1) What is the syntax for accessing (referring to memory) the created object?

You still can't access the contrails addressably through the m_controls collection, because it's also closed, besides you don't know which index corresponds to which particular control. The idea is that CDialog locks access to the elements it consists of, but allows you to manage its main properties consistently. For example we can't access m_caption directly but can change its text using Caption(const string text) method.

What you want is hack in essence. In principle when using any MQ tool you want to make this or that hack, so you are not alone. Probably the easiest way is to copy the library to a separate directory and move the private section to protected. This is crude and dumb, but it will work. Other options are unlikely - too hard code.

 
Vasiliy Sokolov:

You won't be able to access counterparts via m_controls collection anyway, because it is also closed, besides, you don't know which index corresponds to which control. The idea is that CDialog locks access to the elements it consists of, but allows you to manage its main properties consistently. For example we can't access m_caption directly but can change its text using Caption(const string text) method.

What you want is hack in essence. In principle when using any MQ tool you want to make this or that hack, so you are not alone. Probably the easiest way is to copy the library to a separate directory and move the private section to protected. This is crude and dumb, but it will work. The other options are unlikely to work because the code is too hard.

Modifying MQ source code and pulling methods to public is clearly not our method :).
But I can refer to Caption properties after declaration of global variable panel:

CAppDialogPTR panel;

            int total=panel.ControlsTotal();
            for(int i=0;i<total;i++)
            {
               CWnd *_control=panel.Control(i);
               string _control_name=_control.Name();

               if(StringFind(_control_name,"Caption")>0)
               {
                  CEdit *_caption=(CEdit*)_control;
                  _caption.Text("test";
                  _caption.Color(clrRed);
                  ChartRedraw();
                  break;
               }
               
             }

But not only it does not look nice, but this code behind theCAppDialogPTR class. How can I do the same inside ofCAppDialogPTRclass?