Features of the mql5 language, subtleties and tricks - page 40

 
// Возвращает текущее количество объектов классов
int GetAmountObjects( void )
{
  const class CLASS_TMP {} Tmp;
  
  return((int)::StringFormat("%d", &Tmp) - 1);
}
Example application
int OnInit()
{
  if (GetAmountObjects() > 0)
    Print("До " + __FUNCSIG__ + " были вызваны конструкторы!");

  return(INIT_SUCCEEDED);
}
 

the example is taken from the post randomly check

void OnStart()
{
  string Str = "1.23qwedfg";
  
  Print((int)Str);;;;;;;
  Print((double)Str);;;
}

semicolons do not affect the compilation result .... no errors
 
ruslan:

semicolons do not affect the compilation result .... result without errors

There are none.
 

Initialization of static variables by calling functions is an undocumented feature, which appeared by accident, but now it is very problematic to remove.

Calling functions in the trading environment to initialize static variables is strongly discouraged

 
float f = 16777217; // 16777216.0
 
Vladimir Karputov:


There is no need to take the sentence out of context. The phrase goes like this:

To ensure the greatest accuracy in testing, minute bars are also used in real tick mode. Tick data are checked and corrected using them. It also allows to avoid divergence of charts in the tester and in the client terminal.

Does this mean that the history of one-minute bars does not correspond to tick bars?

How is it possible... assuming that the data does correspond to the real trading history?

 
#define  DEFINE_TOSTRING(A) string ToString( const A Var ) { return((string)Var); }
  DEFINE_TOSTRING(char)
  DEFINE_TOSTRING(short)
  DEFINE_TOSTRING(int)
  DEFINE_TOSTRING(long)
  
  DEFINE_TOSTRING(uchar)
  DEFINE_TOSTRING(ushort)
  DEFINE_TOSTRING(uint)
  DEFINE_TOSTRING(ulong)
  
  DEFINE_TOSTRING(bool)
  
  DEFINE_TOSTRING(string)
  
  DEFINE_TOSTRING(double)
  DEFINE_TOSTRING(float)

  DEFINE_TOSTRING(color)  
  
  DEFINE_TOSTRING(datetime)  
#undef  DEFINE_TOSTRING

template <typename T>
string ToString( const T Var ) { return(::EnumToString(Var)); }

void OnStart()
{
  Print(ToString(1));
  Print(ToString(clrRed));
  Print(ToString(TimeCurrent()));
  Print(ToString(ACCOUNT_LOGIN));
}
 
template <typename T>
class IS
{
public:
  template <typename T1>
  static bool Object( const T1* Ptr )
  {
    return(dynamic_cast<const T*>(Ptr) != NULL);
  }
};

class CLASS1 {};
class CLASS2 : public CLASS1 {};
class CLASS3 : public CLASS1 {};

void OnStart()
{
  CLASS2 Object;
  CLASS1* Ptr = &Object;
  
  Print(IS<CLASS1>::Object(Ptr)); // true - Ptr указывает на объект класса CLASS1
  Print(IS<CLASS2>::Object(Ptr)); // true - Ptr указывает на объект класса CLASS2
  Print(IS<CLASS3>::Object(Ptr)); // false - Ptr НЕ указывает на объект класса CLASS3
}
 
Recommendations for measuring the speed of the tester

Run several optimizations (not one!) for 10 passes (50 would be too much). Keep in mind that there is optimization cache, so either recompile EA between optimizations, or change fake parameter enumeration values (this is preferable). Reject 2 extreme values at the top and bottom. Analyze the remaining 6 values from each optimization.

Do not use microsecond timer for mass measurements. Use regular millisecond GetTickCount. Use such a large range of test dates that milliseconds are measured in hundreds and thousands. Then you will get more accurate and stable measuring results.

 
fxsaber:
Recommendations for measuring the tester's execution speed
You forgot to specify that the start of measurement is at the beginning of the first OnTick. The end of the measurement is at the beginning of OnDeinit
Reason: