Errors, bugs, questions - page 2460

 
Please ask ME developers to press CTRL+SHIFT+F and type "MQL5Info". Correct the rudiments found in the resulting SB files.
 
Took me 2 hours to isolate the problem from the project code.
#define  PRINT(x) Print(#x, ":", string(x))

template<typename DATA_TYPE>
struct Wrapper{
   uchar type;
   DATA_TYPE data;
   
   template<typename T>
   void operator=(T value){                  // при замене данной строки на "void operator=(T &value){" происходит перезапись оператора присвоения в классе наследнике B (код не компилируется).
      this.data = value;   
   };
   
   void operator=(DATA_TYPE &_data){
      this.data = _data;   
   };
};

struct A{
   string data;
   
   void operator=(string value){
      data = value;
   };
};

struct B : Wrapper<A>{};


void OnStart(){  
  B b;
  
  string str_value;
  b = str_value;
  
  A a;
  b = a;
  
  B b1;
  b = b1;
}


Using the above code everything works as expected,
however if we try to extend the functionality and add support not only for simple types like (string) from class A, but also for structures,
it turns out that the template assignment operator from the base class overrides the default assignment operators of descendant classes, killing the entire functionality.
Other operators can be used as workarounds, such as "operator*=", but it's a mess.


To developers:
Please add possibility to specify forced code generation for default assignment operator (copy constructor):
class_name & class_name :: operator= ( const class_name & ) = default;  
class_name & class_name :: operator= ( const class_name & ) = delete;   
 

Can you tell me if I use standard indicators in my EA, e.g. iMA,

how do I set their drawing styles to display them correctly in the visualization window?

 
Игорь Евдокимов:

Can you tell me if I use standard indicators in my EA, e.g. iMA,

how can I set drawing styles for them to be displayed correctly in the visualization window?

Like this:Custom Moving Average Input Color

 
Knowledgeable people, a hint! I have a custom symbol based on a real one. How can I make a trade be available from the chart of this symbol? Or is there no such functionality in MT5?
 
Vladimir Karputov:

Like this:Custom Moving Average Input Color

In fact, you have to write your own indicator. Rewriting the standard indicators is not the solution.

The question was exactly how to set the style for the standard indicator.

Is there any other way?

 
In recent versions of MT, as part of the paradigm shift in string handling, it is seen as abandoning the use of NULL-terminated strings.
However, the operation of the StringSetLength function raises a number of questions.

With StringSetLength you can only truncate the length of a string but never increase it, which somehow doesn't make sense.
Is this intended behavior?

#define  PRINT(x) Print(#x, ":", string(x))

void OnStart(){  
  string str = "123456789";
  PRINT(str);
  PRINT(StringLen(str));
  
  
  PRINT(StringSetLength(str, StringLen(str)-1));
  PRINT(str);
  PRINT(StringLen(str));
  
  PRINT(StringSetLength(str, StringLen(str)+2));
  PRINT(str);
  PRINT(StringLen(str));
}

Result:
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      str:123456789
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      StringLen(str):9
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      StringSetLength(str,StringLen(str)-1):true
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      str:12345678
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      StringLen(str):8
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      StringSetLength(str,StringLen(str)+2):false
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      str:12345678
2019.05.15 01:22:08.208 StringFormat_1 (EURUSD,H1)      StringLen(str):8
 
The user would rather shoot himself than implement a "full-fledged"StringSetLength, with "new" characters initialised as 0x0000.

#define  PRINT(x) Print(#x, ":", string(x))

void OnStart(){  
  string str = "123\x0000\x0000\x0000\x0000456789";
  PRINT(str);
  PRINT(StringLen(str));                                                  // StringLen(str):13      StringLen поддерживает работу с 0х0000 short value
  
  PRINT(StringSetLength_using_StringInit(str, 100));                      // false                  StringInit           не поддерживает работу с 0х0000 short value
  PRINT(StringSetLength_using_ShortArrayToString(str, 100));              // false                  ShortArrayToString   не поддерживает работу с 0х0000 short value
  PRINT(StringSetLength_using_StringInit_with_StringFill(str, 100));      // false                  StringFill           не поддерживает работу с 0х0000 short value
}


bool StringSetLength_using_StringInit(string &string_var, int new_length){
   bool result = false;

   int prev_length = StringLen(string_var);
   if(new_length == prev_length){
      result = true;
      return result;
   }
   
   string data = string_var;   
   if(new_length < prev_length){
      StringSetLength(data, new_length);
   }else{
      string string_tail;
      StringInit(string_tail, new_length - prev_length, 0x0000);
      data += string_tail;
   }
   
   if(StringLen(data) == new_length){
      string_var = data;
      result = true;
   }
   return result;
}

bool StringSetLength_using_ShortArrayToString(string &string_var, int new_length){
   bool result = false;

   int prev_length = StringLen(string_var);
   if(new_length == prev_length){
      result = true;
      return result;
   }
   
   string data = string_var;   
   if(new_length < prev_length){
      StringSetLength(data, new_length);
   }else{    
      short data_array[];
      StringToShortArray(data, data_array);
      ArrayResize(data_array, new_length);
      ArrayFill(data_array, prev_length, new_length - prev_length, 0x0000);
      data = ShortArrayToString(data_array, 0, new_length);
   }
   
   if(StringLen(data) == new_length){
      string_var = data;
      result = true;
   }
   return result;
}

bool StringSetLength_using_StringInit_with_StringFill(string &string_var, int new_length){
   bool result = false;

   int prev_length = StringLen(string_var);
   if(new_length == prev_length){
      result = true;
      return result;
   }
   
   string data = string_var;   
   if(new_length < prev_length){
      StringSetLength(data, new_length);
   }else{    
      string string_tail;
      StringInit(string_tail, new_length - prev_length, 0x1111);
      StringFill(string_tail, 0x0000);
      data += string_tail;
   }
   
   if(StringLen(data) == new_length){
      string_var = data;
      result = true;
   }
   return result;
}
 
Sergey Dzyublik:
In recent versions of MT, as part of the paradigm shift in string handling, we see a refusal to use NULL-terminated strings.

Could you elaborate on this idea?

 
rsrozhkov:
Knowledgeable people, can you give me a hint! I have a custom symbol created based on a real symbol. How can I make a trade be available from the chart of this symbol? Or is there no such functionality in MT5?

The answer is self-explanatory. A custom symbol is obtained by some kind of transformation from real symbols. Someone (EA, script or manually) has to do the reverse transformation and send orders for the real symbols.

Reason: