Errors, bugs, questions - page 2465

 
Slava:

Can the tester logs and agent logs (the first 24 are enough) be viewed?

Yes, of course. MT5 (build 2045) same problem.
And MT5 (build 2009) - everything is OK.
Maybe there were some changes compared to MT5 (build 2009), in particular in the logic of determining whether a local agent is running or not (for example, brought it to the logic of network agent detection)...

Files:
 

MT5. build 2055.
ChartGetDouble(0,CHART_PRICE_MAX) and ChartGetDouble(0,CHART_PRICE_MIN) function is executed incorrectly (writes zeros) when changing the TF.
And it writes correctly the first time when starting the indicator. Then when TF is shifted on monthly TF always zeros, on others sometimes at first, then it is normalized.

#property indicator_chart_window
#property indicator_plots   1 
#property indicator_buffers 1

int OnInit()
  {
  Print(EnumToString(_Period) +":  PriceMax="+string(ChartGetDouble(0,CHART_PRICE_MAX))+";  PriceMin="+string(ChartGetDouble(0,CHART_PRICE_MIN)));
   return(INIT_SUCCEEDED);
  }
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }

result:

2019.05.20 02:30:31.689 TestMinMax (NZDUSD,MN1) PERIOD_MN1:  PriceMax=0.8995;  PriceMin=0.3258  // первый раз нормально
2019.05.20 02:30:37.492 TestMinMax (NZDUSD,W1)  PERIOD_W1:  PriceMax=0.8995;  PriceMin=0.3258
2019.05.20 02:30:39.233 TestMinMax (NZDUSD,MN1) PERIOD_MN1:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:30:41.838 TestMinMax (NZDUSD,H4)  PERIOD_H4:  PriceMax=0.6986;  PriceMin=0.6352
2019.05.20 02:30:43.237 TestMinMax (NZDUSD,MN1) PERIOD_MN1:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:30:51.404 TestMinMax (NZDUSD,M1)  PERIOD_M1:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:30:54.108 TestMinMax (NZDUSD,MN1) PERIOD_MN1:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:30:57.420 TestMinMax (NZDUSD,M5)  PERIOD_M5:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:31:00.537 TestMinMax (NZDUSD,M15) PERIOD_M15:  PriceMax=0.0;  PriceMin=0.0
2019.05.20 02:31:02.512 TestMinMax (NZDUSD,M30) PERIOD_M30:  PriceMax=0.679;  PriceMin=0.6477000000000001
2019.05.20 02:31:03.780 TestMinMax (NZDUSD,M15) PERIOD_M15:  PriceMax=0.6689000000000001;  PriceMin=0.649
2019.05.20 02:31:05.977 TestMinMax (NZDUSD,M5)  PERIOD_M5:  PriceMax=0.6593;  PriceMin=0.6502
2019.05.20 02:31:07.502 TestMinMax (NZDUSD,M1)  PERIOD_M1:  PriceMax=0.6541;  PriceMin=0.6508
2019.05.20 02:31:10.136 TestMinMax (NZDUSD,MN1) PERIOD_MN1:  PriceMax=0.0;  PriceMin=0.0
Files:
 

https://www.mql5.com/ru/docs/basis/types/classes

offsetof – это специальная команда, которая непосредственно связана в атрибутом pack. Она позволяет получить смещение члена от начала структуры.

struct Parent{ 
      char              c;    // sizeof(char)=1 
};
     
struct Children pack(2) : Parent{ 
      short             s;   // sizeof(short)=2 
};

void OnStart(){ 
//--- объявим переменную типа Children 
   Children child;   
//--- узнаем смещения от начала структуры  
   Print("offsetof(child.c)=",offsetof(child.c)); 
   Print("offsetof(child.s)=",offsetof(child.s));
}   


At first I was surprised, because I didn't know that offsetof existed.
But the reality put everything in its place:

'offsetof' - function not defined

 
Sergey Dzyublik:

https://www.mql5.com/ru/docs/basis/types/classes

At first I was surprised because I was not aware of the existence of offsetof.
But the reality put everything in its place:

'offsetof' - function not defined

You yourself have written

#include <TypeToBytes.mqh>

Print("offsetof(child.c)=",_OFFSET(child, c)); 
Print("offsetof(child.s)=",_OFFSET(child, s));
 

If you open a signal from the Signals section, you can see an example of an infographic:



Normally, the purpose of an infographic is to convey to the end user the pros and cons of a set of properties of the object being analysed.
However, the essence of this infographic is not clear, when a 100% drawdown is displayed as a 100% result on the chart.
Also the same indicator is used twice within the same chart: once in positive and the second time in negative terms (indicators of "Profitable Trades" and "Losing Trades").

Proposed changes:
1. Introduce a countdown for the indicators "Maximum drawdown", "Maximum deposit load", "Losing trades" (the smaller value - the larger indicator value on the chart);
2. Replace one of the duplicated indicators ("Profitable trades" or "Losing trades") with a new indicator (for example, average deviation of the amount of buy to sell, or something else);
3. For certain indicators, such as "Maximum drawdown" and "Maximum deposit load", replace the ubiquitous % scale on the chart with a logarithmic or other display scale. The objective is to increase the impact of the indicator on signal attractiveness.

 
class A{
   int  data;
};

struct Wrap{
   A arr[];
};
   
   
void OnStart(){  
   Wrap data_1;
   ArrayResize(data_1.arr, 10);
   
   Wrap data_2 = data_1;
   PRINT(ArraySize(data_2.arr));      // result: 10
   
   A arr[];
   PRINT(ArrayCopy(arr, data_1.arr)); //'arr' - structures or classes containing objects are not allowed
}


Why structures can do deep copy, butArrayCopy, even when the class has a copy constructor, can't do anything and gives a compilation error?
"It's not normal, it's not fair!" ©

 
bool  ArrayInsert( 
   void&        dst_array[],          // receiving array 
   const void&  src_array[],          // source array 
   uint         dst_start,            // receiver array index to be inserted 
   uint         src_start=0,          // source array index to be copied 
   uint         count=WHOLE_ARRAY     // number of elements to insert 
   );
int  ArrayCopy( 
   void&        dst_array[],         // destination array 
   const void&  src_array[],         // source array 
   int          dst_start=0,         // index starting from which write into destination array 
   int          src_start=0,         // first index of a source array 
   int          count=WHOLE_ARRAY    // number of elements 
   );

Differences in almost "identical" functions:
1. no default parameter for ArrayInsert.
2. lack of a "standard" parameter description.

The use of different data types for the same parameters (int, uint) can be understood, referring to compatibility.
 
Sergey Dzyublik:
No default parameter for ArrayInsert.
It is not needed there.
But the fact that the function returns a bool, when it should return the number of elements added...
 
Sergey Dzyublik:


Why structures can do deep copy, butArrayCopy, even when the class has a copy constructor, can't do anything and gives a compilation error?
"It's not normal, it's not fair!" ©

I had to implement a full-fledged ArrayCopy myself.
I don't think so, but maybe somebody may find it useful...

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

template<typename T>
uint  ArrayCopy_bypass( 
   T&            dst_array[],         // destination array 
   const T&      src_array[],         // source array 
   uint          dst_start=0,         // index starting from which write into destination array 
   uint          src_start=0,         // first index of a source array 
   uint          count=WHOLE_ARRAY    // number of elements 
   )
{
   uint src_size = ArraySize(src_array);
   uint dst_size = ArraySize(dst_array);
   bool src_array_is_dynamic = ArrayIsDynamic(src_array);
   bool dst_array_is_dynamic = ArrayIsDynamic(dst_array);
   
   // validate input parameters
   if(src_size <= src_start 
      || ( !dst_array_is_dynamic && (dst_size <= dst_start))){
      return 0;
   }
   
   uint max_allowed_array_size = uchar(INT_MAX);
   uint same_array_check_min_count_limit = 5;
   
   //--- the same array could be passed to dst_array and src_array parameters
   bool same_array_is_used = true;
   bool dst_array_resize_was_applied = false;
   if (src_size != dst_size || src_array_is_dynamic != dst_array_is_dynamic){
      same_array_is_used = false;
   }
   
   //--- normalize copy count based on src_array data
   if(count == uint(WHOLE_ARRAY) || count > src_size - src_start){
      count = src_size - src_start;
   }
   
   //--- normalize copy count based on dst_start data
   uint dst_required_size = dst_start + count;
   if (dst_required_size > max_allowed_array_size){
      return 0;
   }
   
   if(dst_size <= dst_required_size){
      if(dst_array_is_dynamic){
         ArrayResize(dst_array, dst_required_size);
         dst_array_resize_was_applied = true;
         
         dst_size = ArraySize(dst_array);
         src_size = ArraySize(src_array);
         
         if(same_array_is_used && src_size != dst_size){
            same_array_is_used = false;
         }
      }    
      count = dst_size - dst_start;
   }
   
   //--- check copy count
   if(count == 0){
      return 0;
   }
   
   //--- the same array could be passed to dst_array and src_array parameters, let's confirm it
   if(count >= same_array_check_min_count_limit 
         && same_array_is_used 
         && !dst_array_resize_was_applied)
   {
      if(dst_array_is_dynamic && dst_size + 1 <= max_allowed_array_size){
         ArrayResize(dst_array, dst_size + 1);
         dst_array_resize_was_applied = true;
         
         if(ArraySize(src_array) != dst_size + 1){
            same_array_is_used = false;
         }
         ArrayResize(dst_array, dst_size);
      }
   }
   
   //copy arrays
   if(same_array_is_used){
      T src_copy[];
      ArrayResize(src_copy, count);
      
      for(uint i = 0; i < count; i++){
         src_copy[i] = src_array[src_start + i];
      }
      
      for(uint i = 0; i < count; i++){
         dst_array[dst_start + i] = src_copy[i];
      }
   }else{
      for(uint i = 0; i < count; i++){
         dst_array[dst_start + i] = src_array[src_start + i];
      }
   }
   return count;
}
   
   
class A{
   uchar data;
};
   
   
void OnStart(){
   uchar test_data[10] = {0,1,2,3,4,5,6,7,8,9};
   
   PRINT("TEST 1 (Static)");     
   uchar data_1[8]; 
   
   PRINT(ArrayCopy_bypass(data_1, test_data));
   ArrayPrint(data_1);
   
   PRINT(ArrayCopy_bypass(data_1, test_data, 1, 0, 1));
   ArrayPrint(data_1);
   
   PRINT(ArrayCopy_bypass(data_1, test_data, 5));
   ArrayPrint(data_1);
   
   PRINT(ArrayCopy_bypass(data_1, test_data, 30, 8, 5));
   ArrayPrint(data_1);
   
   
   PRINT("TEST 2 (DYNAMIC)");  
   uchar data_2[]; 
   
   PRINT(ArrayCopy_bypass(data_2, test_data));
   ArrayPrint(data_2);
   
   PRINT(ArrayCopy_bypass(data_2, test_data, 1, 0, 1));
   ArrayPrint(data_2);
   
   PRINT(ArrayCopy_bypass(data_2, test_data, 5));
   ArrayPrint(data_2);
   
   PRINT(ArrayCopy_bypass(data_2, test_data, 30, 8, 5));
   ArrayPrint(data_2);
   
   
   A data_a1[10];
   A data_a2[];
   ArrayCopy_bypass(data_a2, data_a1);            //10
   //PRINT(ArrayCopy(data_a2, data_a1));          //'data_a2' - structures or classes containing objects are not allowed
}


Result:

2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      TEST 1 (Static):TEST 1 (Static)
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_1,test_data):8
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 1 2 3 4 5 6 7
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_1,test_data,1,0,1):1
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 5 6 7
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_1,test_data,5):3
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 0 1 2
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_1,test_data,30,8,5):0
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 0 1 2
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      TEST 2 (DYNAMIC):TEST 2 (DYNAMIC)
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_2,test_data):10
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 1 2 3 4 5 6 7 8 9
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_2,test_data,1,0,1):1
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 5 6 7 8 9
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_2,test_data,5):10
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 0 1 2 3 4 5 6 7 8 9
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      ArrayCopy_bypass(data_2,test_data,30,8,5):2
2019.05.21 00:27:59.870 Test_ArrayCopy (EURUSD,H1)      0 0 2 3 4 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 9
 
Good afternoon.
Can someone tell me how to make the balance sheet report in the last Profit window also include swap and commission!
Or how to do it?
It is not convenient to look at profit and then you realize that the commission and swaps should be subtracted. It is terribly annoying!
Reason: