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

 
Alexey Navoykov:

Another convenient variant would be protected inheritance, when the base class has all methods, and in an inherited class you only show Get.And when needed, you bring it to the base class.

I used protected inheritance, but messed up with the selected one. Thank you!

But Metaeditor still hasn't fixed the bug that all these methods are dumped to the list even if they are unavailable.

I didn't check it now, but when I was experimenting, it was stored in my memory that they don't drop out.

 

Before modifying or deleting an order, you need to do a check

OrderGetInteger(ORDER_STATE) == ORDER_STATE_PLACED 

SB does not have it, so you have to write it yourself.


In the Tester this check is meaningless - all current orders always have this status.

 

Forum on trading, automated trading systems and trading strategies testing

Market closed

fxsaber, 2017.09.22 09:45

// Время последнего тика символа
long GetSymbolTime( const string Symb )
{
  MqlTick Tick;
  
  return(SymbolInfoTick(Symb, Tick) ? Tick.time_msc : 0);
}

// Время последнего тика Обзора рынка
long GetMarketWatchTime( void )
{
  long Res = 0;
  
  for (int i = SymbolsTotal(true) - 1; i >= 0; i--)
  {
    const long TmpTime = GetSymbolTime(SymbolName(i, true));
    
    if (TmpTime > Res)
      Res = TmpTime;
  }
  
  return(Res);
}

// Текущее время на торговом сервере без учета пинга
long GetCurrenTime( void )
{
  static ulong StartTime = GetMicrosecondCount();
  static long PrevTime = 0;
  
  const long TmpTime = GetMarketWatchTime();
  
  if (TmpTime > PrevTime)
  {
    PrevTime = TmpTime;
    
    StartTime = GetMicrosecondCount();
  }
  
  return(PrevTime + (long)((GetMicrosecondCount() - StartTime) / 1000));
}

void OnInit()
{
  MarketBookAdd(_Symbol);
}

void OnDeinit( const int )
{
  MarketBookRelease(_Symbol);
}

string TimeToString( const long Value )
{
  return((string)(datetime)(Value / 1000) + "." + (string)IntegerToString(Value % 1000, 3, '0'));
}

void OnBookEvent( const string& )
{
  Comment(TimeToString(GetCurrenTime()));
}
 

POSITION_TIME_UPDATE refers only to the change of the position's lot. For example, a partial closing of a position on any type of account or a fill on a netting.

Changes in SL/TP levels do not affect POSITION_TIME_UPDATE.

To paraphrase, POSITION_TIME_UPDATE is only affected by modifications reflected in the Trade History - trades. SL/TP-levels do not belong to such modifications, so they do not affect them.

 

Forum on trading, automated trading systems and trading strategies testing

EA Reinitialization

fxsaber, 2017.09.26 11:35

// Перезапуск себя
bool ExpertReopen()
{
  return(ChartSaveTemplate(0, __FILE__) && ChartApplyTemplate(0, __FILE__));
}
 

Forum on trading, automated trading systems and trading strategies testing

Bugs, bugs, questions

fxsaber, 2017.09.08 11:11

struct A
{
  int i;
};

struct B : public A {};

void OnStart()
{
  A a = {0};
  B b;
  
  b = (B)a; // cannot cast 'A' to 'B'
  
  b = a;    // так без проблем
}
From SR.

It's all right here.

In the first case it's a cast, in the second it's an assignment.

Derivation from the parent to the descendant is unacceptable

Assignment to an object is a call to the corresponding copy operator, in this case implicit A::operator=(const A &)

Thanks, so the parent copy operator remains available outsideonly in case of public inheritance. Checked it out, that's right.

struct A
{
  int i;
};

struct B : protected A {};

void OnStart()
{
  A a = {0};
  B b;
  
  b = a;    // 'A::operator=' - cannot access protected member function
}

Is it good?

With this construct we need to declare an additional copy constructor B::operator=(const A&) and "pass through" the call to A::operator= in it

 

Variants of standard indicators calculation on custom data (without creation of additional indicators).

Базовые индикаторы, применяемые к кастомному инструменту
Базовые индикаторы, применяемые к кастомному инструменту
  • 2017.09.27
  • www.mql5.com
Здравствуйте. Задавал этот вопрос на английском форуме...
 

Forum on trading, automated trading systems and trading strategies testing

Market closed

fxsaber, 2017.09.22 09:45

// Время последнего тика символа
long GetSymbolTime( const string Symb )
{
  MqlTick Tick;
  
  return(SymbolInfoTick(Symb, Tick) ? Tick.time_msc : 0);
}

// Время последнего тика Обзора рынка
long GetMarketWatchTime( void )
{
  long Res = 0;
  
  for (int i = SymbolsTotal(true) - 1; i >= 0; i--)
  {
    const long TmpTime = GetSymbolTime(SymbolName(i, true));
    
    if (TmpTime > Res)
      Res = TmpTime;
  }
  
  return(Res);
}

We should throw out the custom symbols from the loop, because in Market Watch they can be set to any time, even 3000 years.

 
In MQL5 it is acceptable to write it like this
void OnTick()
{  
  double Buffer[];
  
  CopyBuffer(iMA(NULL, PERIOD_CURRENT, 1, 0, MODE_SMA, PRICE_CLOSE), 0, 0, 1, Buffer);
}

I.e. "create" a handle on every tick. New indicator entities will not be created, the time will be wasted only on the comparison of the iMA input parameters with those indicators that were running on the previous ticks. I.e., exactly the same thing that is done in MT4.

 
fxsaber:
In MQL5 it is quite acceptable to write it like this

I.e. "create" a handle on every tick. New indicator entities will not be created, the time will be wasted only on the comparison of the iMA input parameters with those indicators that were running on the previous ticks. I.e., exactly the same thing that is done in MT4.

Have you measured the performance? It is interesting, how much it will slow down the performance. Especially for custom indicators.

Reason: