Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1320

 
pivomoe:

After upgrading to version 2981, an error has started to appear in the line

Please advise how to replace this line.

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

Ilyas, 2021.05.28 18:18

We are expanding our initializing sequences "{ ... }". In the next build we'll allow to use any expression, not only constant.

In place of this change, there will be a restriction on using constants for enumerations (as for an ordinary expression): if the constant does not belong to the enum, the corresponding error will be produced.

Analysis of existing codes has shown that the single zero sequence "{0}" is often used incorrectly.

For example, like this:

MqlTradeRequest request={0};


Such a notation means to set the value of zero for the first field of the structure and zero out the rest of the fields.

For the above code line, according to the new rules, there will be an error since the first field has the type ENUM_TRADE_REQUEST_ACTIONS, an enumeration that lacks the value "0".

cannot convert 0 to enum 'ENUM_TRADE_REQUEST_ACTIONS'


The correct way would be:

MqlTradeRequest request={};

 
Thank you.
 
Kira27:

So I'm writing -- which class should I inherit my class from to use these methods from their standard library?

What's wrong with my question? ))))

 

Here's the code, what's wrong?

//+------------------------------------------------------------------+
//|                                            Test_Nasledovania.mqh |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Object.mqh>
#include <Trade\Trade.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class Test_Nasledovania : public CObject
  {
private:

public:
                     Test_Nasledovania();
                    ~Test_Nasledovania();

   void              test();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
Test_Nasledovania::Test_Nasledovania()
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
Test_Nasledovania::~Test_Nasledovania()
  {
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void      Test_Nasledovania::test()
{
Buy  -- Метод Buy не высвечивается как подключеный
}
//+------------------------------------------------------------------+

The class includes


The class Test_Nasledovania : public CObject itself is an heir of the base class CObject of the whole standard library.)

 
Kira27:

Here's the code, what's wrong?

The class includes


The Test_Nasledovania : public CObject class itself is an heir of the CObject base class of the entire standard library.)

In addition to connecting the trading class, you also need to create an object of the trading class, and then refer to the methods of the class through the created object

***
#include <Trade\Trade.mqh>
//---
CTrade         m_trade;                      // object of CTrade class
***
void OnTick()
  {
   m_trade.Buy(***
  }
 
Kira27:

What's wrong with my question? ))))

Because the help has the whole inheritance of all these classes written in black and white.

 
Vladimir Karputov:

In addition to connecting a trading class, you also need to create an object of this trading class and then refer to the methods of the class through the created object

The question about using class methods in Expert Advisors and scripts is of course, the creation of objects. But the question is about using methods of a base class, in a descendant class. Why do we need to create objects there?

 
Kira27:

About using methods of classes, in Expert Advisors and scripts, it goes without saying that we create objects. But the question is about using methods of a base class, inside a descendant class. Why do you need to create objects there?

You have inherited your class from CObject:

class Test_Nasledovania : public CObject

Excuse me, but what methods were you expecting to see?

Документация по MQL5: Стандартная библиотека / Базовый класс CObject
Документация по MQL5: Стандартная библиотека / Базовый класс CObject
  • www.mql5.com
Базовый класс CObject - Стандартная библиотека - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Here is an example of using methods of a base class inside an inherited class without using an object

#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//#include <Object.mqh>
#include <Trade\Trade.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class Test_Nasledovania : public CTrade
  {
private:

public:
                     Test_Nasledovania();
                    ~Test_Nasledovania();

   void              test();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
Test_Nasledovania::Test_Nasledovania()
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
Test_Nasledovania::~Test_Nasledovania()
  {
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void      Test_Nasledovania::test()
{
Buy
}
//+------------------------------------------------------------------+

I want to use so all the methods included in

What class should I inherit my class from, so that I can use methods of all these classes inside my class without creating objects? If it's possible at all)))

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Artyom Trishkin:

You inherited your class from CObject:

Sorry, what methods were you expecting to see?

I agree))), I was stupid))), the base class of all these methods, does not allow to use methods of classes of its descendants)))