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

 
In the tester, it is possible to find out the current time correctly only throughTimeTradeServer(), not TimeCurrent().
 
fxsaber:
In the tester, it is only possible to find out the current time correctly throughTimeTradeServer(), not TimeCurrent().
A highly questionable statement.
 
Slava:
This is a very controversial statement.
void OnTick()
{
  Print(TimeCurrent());
  
  Sleep(3600 * 1000);
  
  Print(TimeCurrent());
  Print(TimeTradeServer());    
  
  ExpertRemove();
}

Result

2017.10.02 00:03:03   2017.10.02 00:03:03
2017.10.02 01:03:03   2017.10.02 01:02:59
2017.10.02 01:03:03   2017.10.02 01:03:03


TimeCurrent returns the time of the last tick of the main symbol, not the tester (server). It's not possible to find out the exact current time of the server in milliseconds.

 

Good afternoon. I read about the service arrays https://www.mql5.com/ru/docs/constants/objectconstants/enum_anchorpoint ( in the last example)

double Ups[],Downs[];
datetime Time[];

Is there a list of all service arrays somewhere?

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Способы привязки объектов
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Способы привязки объектов
  • www.mql5.com
Графические объекты Text, Label, Bitmap и Bitmap Label (OBJ_TEXT, OBJ_LABEL, OBJ_BITMAP и OBJ_BITMAP_LABEL) могут иметь один из 9 различных способов привязки своих координат, задаваемых свойством OBJPROP_ANCHOR. – объекты имеет ширину и высоту. Если указано "только для чтения", то это означает, что значения ширины и высоты вычисляются...
 
i have been following this signal one more week i will follow

and then lets see

en/signals/352123

 

A language technique that allows the use of protected methods/fields.

Example

#include <Canvas\Canvas.mqh>

// Помещает картинку в ресурс
bool ToResource( const string Name, const uint &Data[], const uint Width )
{
  return(::ResourceCreate(Name, Data, Width, (Width == 0) ? ::ArraySize(Data) : ::ArraySize(Data) / Width, 0, 0, Width, ::COLOR_FORMAT_ARGB_NORMALIZE));
}

// Прием использования protected полей/методов
class CANVAS : public CCanvas
{
public:
  // Загрузка картинки из BMP-файла
  static bool BMPToArray( const string FileName, uint &Data[], int &Width )
  {
    CANVAS Canvas;
    
    const bool Res = Canvas.LoadFromFile(FileName);
    
    if (Res)
    {
      ArrayCopy(Data, Canvas.m_pixels);
      
      Width = Canvas.m_width;
    }
    
    return(Res);
  }
};

// Грузим BMP с альфаканалом не из ресурса, а из файла
void OnStart()
{     
  const string Resource = "::Resource";
         
  uint Data[], Width;   
  
  if (CANVAS::BMPToArray("Picture.bmp", Data, Width) &&
      ToResource(Resource, Data, Width))
  {
   ObjectCreate(0, __FILE__, OBJ_BITMAP_LABEL, 0, 0, 0);   
   ObjectSetString(0, __FILE__, OBJPROP_BMPFILE, Resource);
        
   // Сконвертировали BMP в PNG (без учета прозрачности)
   BitmapObjectToFile(0, __FILE__, "Picture.png"); // https://www.mql5.com/ru/forum/170952/page57#comment_5985505
  }
}
 
 
Because of this peculiarity

typing of the template parameters is strict, specialization with implicit conversion is unacceptable

it is possible to write functions that take as input parameters pointers only a base class, and their descendants are discarded at compile time.


Example

template <typename T>
void StrongCondition( T, T ) {}

class A
{
public:
  int i;
  
  template <typename T>  
  void SetStong( T Value )
  {
    StrongCondition(&this, Value);
    
    this.i = Value.i;
  }
  
  void Set( A* Value )
  {
    this.i = Value.i;
  }
};

class B : public A {};

void OnStart()
{
  A a;
  B b;
  
  a.Set(&b);   
  a.SetStong(&a);
  
  a.SetStong(&b);       // потомки в явном виде запрещены
  a.SetStong((A*)(&b)); // только явное приведение разрешено
}
 
Can I change fieldsof the const-objectclass or call its non-const-methods? -You may!
template <typename T>
T GetMe( const T Ptr )
{
  return((T)Ptr);
}

class A
{
public:  
  int i;
};

void OnStart()
{
  const A a;

  GetMe(&a).i = 1;
  
  Print(a.i); // 1
}

I don't like this trick myself. I thought I was insured against unauthorized access. Bummer, though! Of course, it does not work with const-structures. So keep this loophole in mind.

 
Reason: