Errors, bugs, questions - page 1871

 
Slava:
And it should not be possible to


1. When is union planned to be introduced?

2. will typedefs be entered as well?

3. are pointers to fundamental types planned to be introduced?
 
Konstantin:


1. when is union planned to be introduced?

2. will typedef also be introduced with union?

3. Is introduction of pointers to fundamental types planned?

1. Soon. Everything is ready in the compiler, we are testing it now. We will release it after the tests.

2. It is not known yet when

3. no, not planned.

 

For some reason,CopyTime (or any similar)resizes the receive array, evenif thesize of the receive array is larger than the size to be copied.

Gentlemen, is it normal? Has it always been like this? Or a bug?

For example:

static datetime TimeBuf[]; 

if (ArraySize(TimeBuf) == 0) ArrayResize(TimeBuf, 10);

CopyTime(_Symbol, _Period, 0, 1, TimeBuf);

The CopyTime function resizes the TimeBuf array to 1.

This is wrong in principle.

It wouldn't be a problem but for one important nuance: the data are copied to the beginning of the array and, consequently, the whole point of optimization is lost at the root.

 
Marat Sultanov:

For some reason,CopyTime (or any similar)resizes the receive array, evenif thesize of the receive array is larger than the size to be copied.

Gentlemen, is it normal? Has it always been like this? Or a bug?

For example:

The CopyTime function resizes the TimeBuf array to 1.

This is wrong in principle.

It wouldn't be so bad, were it not for one important nuance: the data are copied at the beginning of the array, and consequently, the whole point of optimization is lost at the root.

Your array is dynamic! That is, with a variable size. As you have not specified its dimension in square brackets.

The word static means that the object of this array is constructed when the Expert Advisor is loaded, and is destroyed when it is unloaded.

 
Slava:

Your array is dynamic! That is, with a variable size. As you didn't specify its dimension in square brackets.

The word static means that object of this array is constructed at loading of EA and destroyed at unloading

I'm sorry, but you missed the point.

Let the array be declared in the global scope

datetime _TimeBuf[]; 

void OnTick()
{}

Then:

1) The first time we copy (CopyTime) into the array how many bars there are.

datetime _TimeBuf[];
int      _BarsCountReserveSize;

void OnTick()
{
   int BarsCount = Bars(_Symbol, _Period);
   
   if (ArraySize(_TimeBuf) == 0)
   { 
      if (_BarsCountReserveSize <= BarsCount) _BarsCountReserveSize = (int)ceil(BarsCount*1.3);

      ArrayResize(_TimeBuf, BarsCount, _BarsCountReserveSize);

      CopyTime(_Symbol, _Period, 0, BarsCount, _TimeBuf);
   }
}

2) According to the optimal design, when a new bar appears, we don't want to copy all the bars, right? Therefore, we decide to copy only the last 2 modified bars.

datetime _TimeBuf[];
int      _BarsCountReserveSize;

void OnTick()
{
   int BarsCount = Bars(_Symbol, _Period);
   
   if (ArraySize(_TimeBuf) == 0)
   { 
      _BarsCountReserveSize = (int)ceil(BarsCount*1.3);

      ArrayResize(_TimeBuf, BarsCount, _BarsCountReserveSize);

      CopyTime(_Symbol, _Period, 0, BarsCount, _TimeBuf);
   }
   else
   {
      int RequiredCount = BarsCount - ArraySize(_TimeBuf) + 1;
      
      ArrayResize(_TimeBuf, RequiredCount, _BarsCountReserveSize);

      CopyTime(_Symbol, _Period, 0, RequiredCount, _TimeBuf);
   }
}

3) In the end our optimization doesn't work, becauseCopyTime resizes the array and puts the size =RequiredCount, plus we lose the reserve size(CopyTime is not aware of it).

 

This situation would not occur if CopyTime copied directly from the end of the array to the starting point:

at the location:

_TimeBuf[0] = D'2017.01.01';
_TimeBuf[1] = D'2017.01.02';
_TimeBuf[2] = D'2017.01.03';

it:

const int ArrSize = ArraySize(_TimeBuf);

_TimeBuf[ArrSize-3] = D'2017.01.01';
_TimeBuf[ArrSize-2] = D'2017.01.02';
_TimeBuf[ArrSize-1] = D'2017.01.03';
 

Copy functions have always changed the size of a dynamic array. To a larger or smaller size. But there was always a clear correspondence with the number of records given as a result of the query.

In your case the original query to an array with dynamically resizable. All other requests that request one element at a time, do it in an array with a predefined size (datetime _TimeBuf1[1]), so there is no redistribution. Self-reallocate the received element to a large dynamic array

 

So it's always been like that and it's normal. I see. Thank you for your reply!

I was aware of the enlargement, but not of the shrinking to the size of the requested data. Now I'll know, thank you!

 

MT4 build 1065

Test on USDJPY TF M15

from the result log:

406 2014.11.28 20:30 sell 18 5.50 118.641 0.000 117.015 0.00
521 2014.12.09 17:15 t/p 18 5.50 118.386 0.000 118.386-148.95

How does the loss come about?
 
-Aleks-:

How does the loss come about?

Swap.
Reason: