Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1187

 
leonerd:

but is it possible to declare a class as a base class and then, depending on the conditions, override it as one of the inherited classes?

The task is to leave the class name the same in the code.

Also, please advise which directive to use to define the tester.

Is it possible to do it this way?

#include <NewsFilter.mqh>
//...
   if(MQLInfoInteger(MQL_TESTER))
      CNewsFilterTester news_filter;
   else
      CNewsFilter       news_filter;
//---
   news_filter.Init(Symbol(),MagicNumber);
 
Artyom Trishkin:

Thank you. Yes, but here the news_filter object turns out to be undefined. It must be declared globally to be accessible from anywhere in the code. What to do?

CNewsFilter       news_filter;
void OnInit()
  {
  }
 
leonerd:

Thank you. Yes, but here the news_filter object turns out to be undefined. It must be declared globally to be accessible from anywhere in the code. What to do?

In what cases would it be undefined?

 
Artyom Trishkin:

In which cases will it be indefinite?

#include <NewsFilter.mqh>

void OnInit()
  {
//...
   if(MQLInfoInteger(MQL_TESTER))
      CNewsFilterTester news_filter;
   else
      CNewsFilter       news_filter;
//---
   news_filter.Init(Symbol(),MagicNumber);
  }
void OnTick()
  {
   news_filter.Check()...
  }
 

Please help me understand the logic behind the execution of this statement and the expression of its condition.


CTrade         m_trade;

CPositionInfo  m_position;

if(!m_trade.PositionClose(m_position.Ticket()))

If it does NOT close the position defined by the ticket?

First it gets a position ticket -> the program tries to close the position -> the returned boolean value is reversed.

Right?

 
odyn:

Please help me understand the logic behind the execution of this statement and the expression of its condition.


If it does NOT close the position defined by the ticket?

First it gets a position ticket -> the program tries to close the position -> the returned boolean value is reversed.

Right?

-> Returns true if the position with the specified ticket is closed, otherwise false

Condition reads: If position with specified ticket is not closed...

 
Сергей Таболин:

-> Returns true if position with specified ticket is closed, otherwise false

Condition reads: If position with specified ticket is not closed...

The question is, is the program trying to close the position or not?

 
odyn:

The question is, does the programme try to close the position or not?

Yes, it does.

 
Сергей Таболин:

Yes, he is.

Thank you for your reply

 

Please explain.

TheOnTradeTransaction function.

Does it have to be in the Expert Advisor?

If not, in what cases should it be included in the code? And why?