Errors, bugs, questions - page 2469

 

I'll know ) then hack

 

I am transferring a program from MQL4 to MQL5.

I have faced this error.

On timeframes up to m30 the Period() value is correct.

2019.05.22 17:45:38.628 TestStat (GBPUSD,M15) 4854 Period()=15
2019.05.22 17:46:08.267 TestStat (GBPUSD,M30) 4854 Period()=30

From timeframe H1 I get incomprehensible values.

2019.05.22 17:31:07.446 TestStat (GBPUSD,H1) 4854 Period()=16385
2019.05.22 17:46:39.362 TestStat (GBPUSD,H4) 4854 Period()=16388
2019.05.22 17:46:55.552 TestStat (GBPUSD,D1) 4854 Period()=16408

Terminal version build 2057 dated 21 May 2019.

 

Thank you.

In the description:

Period

Returns the timeframe value of the current chart.

ENUM_TIMEFRAMESPeriod();

Returned value

Contents of the _Period variable, holding the timeframe value of the current chart. Value can be one ofthe ENUM_TIMEFRAMESenumerationvalues .

See also

PeriodSeconds, Chart Periods, Date and Time, , Object Visibility

=================

That's not very well done. It should be correctly written in the description. You should not look for the source of the problem on the forum.

It turns out that Period() won't give out the value of the current timeframe as it says:The value can be one of the values of enumeration ENUM_TIMEFRAMES.

But something else entirely.

Please correct the language description for developers.

 
Thanks again toTheXpert for providing the code.
We have the following results on ArrayResize capacity MT5(build 2057):

#import "msvcrt.dll"
  long memcpy(int &dst[], long &src, int cnt);
#import

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

template<typename T>
struct ArrayStore
{
   long offset;
   T x[];
   
   int capacity() 
   {
      int ints[sizeof(ArrayStore) / sizeof(int)];
      memcpy(ints, this.offset, sizeof(ArrayStore));
      return ints[8];
   }
   
   int size() 
   {
      int ints[sizeof(ArrayStore) / sizeof(int)];
      memcpy(ints, this.offset, sizeof(ArrayStore));
      return ints[4];
   }
};

template<typename T>
int TestArrayCapacity(ArrayStore<T> &store, int size, int reserved_size = 0){
   ArrayResize(store.x, size, reserved_size);
   return store.capacity(); 
}

template<typename T>
int TestArraySize(ArrayStore<T> &store, int size, int reserved_size = 0){
   ArrayResize(store.x, size, reserved_size);
   return store.size(); 
}


void OnStart()
{
   ArrayStore<int> store;
   
   PRINT("TEST_ArrayCapacity");
   
   PRINT(TestArrayCapacity(store, 100, 0)); 
   PRINT(TestArrayCapacity(store, 100, 100)); 
   PRINT(TestArrayCapacity(store, 101, 100)); 
   PRINT(TestArrayCapacity(store, 200, 100)); 
   PRINT(TestArrayCapacity(store, 201, 100)); 
   PRINT(TestArrayCapacity(store, 202, 100)); 
   PRINT(TestArrayCapacity(store, 100,   1)); 
   PRINT(TestArrayCapacity(store, 100, 400)); 
   PRINT(TestArrayCapacity(store, 300, 400)); 
   PRINT(TestArrayCapacity(store, 301, 600));
   PRINT(TestArrayCapacity(store, 302, 600));
   PRINT(TestArrayCapacity(store, 303, 600));
   PRINT(TestArrayCapacity(store, 100,   0)); 
   PRINT(TestArrayCapacity(store, 100, 100)); 
   PRINT(TestArrayCapacity(store, 100,  -1)); 
   PRINT(TestArrayCapacity(store, 100, 100)); 
   PRINT(TestArrayCapacity(store, 105, 100)); 
}

Result:
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TEST_ArrayCapacity:TEST_ArrayCapacity
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,0):100
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,100):100
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,101,100):201
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,200,100):201
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,201,100):201
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,202,100):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,1):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,400):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,300,400):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,301,600):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,302,600):302
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,303,600):903
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,0):903
2019.05.22 17:00:50.249 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,100):903
2019.05.22 17:00:50.250 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,-1):100
2019.05.22 17:00:50.250 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,100,100):100
2019.05.22 17:00:50.250 Test_array_resize (EURUSD,H1)   TestArrayCapacity(store,105,100):205
 
Eugeni Neumoin:

Description:

Contents of the _Period variable, which stores the timeframe value of the current chart. The value can be one of the values of ENUM_TIMEFRAMESenumeration.

This is not done well. It should be correctly written in the description. You should not look for the source of the problem on the forum.

So nowhere is it written that this value equals the period in minutes (as it was in quad).

https://www.mql5.com/ru/articles/81

That's where the link article starts.

Переход с MQL4 на MQL5
Переход с MQL4 на MQL5
  • www.mql5.com
Данная статья, построенная в форме справочника по функциям MQL4, призвана помочь переходу с MQL4 на MQL5. Для каждой функции языка MQL4 приведено описание и представлен способ ее реализации на MQL5, что позволит вам значительно ускорить перевод своих программ с MQL4 на MQL5. Для удобства функции разбиты на группы, как в документации по MQL4.
 
Igor Zakharov:

So nowhere does it say that this value is equal to the period in minutes (as it was in fours).

https://www.mql5.com/ru/articles/81

This is where the article on the link starts.

There is a description of the language that says: Value can be one of the values of ENUM_TIMEFRAMESenumeration.

See the language description further down:

Graph periods

All predefined chart periods have unique identifiers. The PERIOD_CURRENT identifier means the current period of the chart, at which the mql5 program is running.

ENUM_TIMEFRAMES

Identifier

Description

PERIOD_CURRENT

Current period

PERIOD_M1

1 minute

PERIOD_M2

2 minutes

PERIOD_M3

3 minutes

PERIOD_M4

4 minutes

PERIOD_M5

5 minutes

PERIOD_M6

6 minutes

PERIOD_M10

10 minutes

PERIOD_M12

12 minutes

PERIOD_M15

15 minutes

PERIOD_M20

20 minutes

PERIOD_M30

30 minutes

PERIOD_H1

1 hour

PERIOD_H2

2 hours

PERIOD_H3

3 hours

PERIOD_H4

4 hours

PERIOD_H6

6 hours

PERIOD_H8

8 hours

PERIOD_H12

12 hours

PERIOD_D1

1 day

PERIOD_W1

1 week

PERIOD_MN1

1 month

======================

And nowhere in the description does it say that this value is in seconds.

The description should say it all.

And when you have to look up some other articles, that's too bad.

 
Sergey Dzyublik:
Thanks again toTheXpert for providing the code.
We have the following results on ArrayResize capacity MT5(build 2057):
So, conclusions on ArrayResize performance and impact on real capacity:

1. The first ArrayResize is very important, it really allocates memory taking into account size + reserved_size and sets capacity.
2. All subsequent ArrayResize executions with a new value of reserved_size have no effect on the amount of allocated memory and capacity, respectively.
3 New memory allocation is performed only when capacity is exceeded and in this case size + reserved_size is used again to determine the amount of allocated memory and set a new capacity.
4. A value of reserved_size < 0 releases the reserved memory to size size.
 
Eugeni Neumoin:

And nowhere in the description does it say that this value is in seconds.

So it's not in seconds...

 
Eugeni Neumoin:

There is a language description that says: Value can be one of the ENUM_TIMEFRAMESenumeration values .

See further in the language description:

Graph periods

All predefined chart periods have unique identifiers. The PERIOD_CURRENT identifier means the current period of the chart, at which the mql5 program is running.

ENUM_TIMEFRAMES

======================

And nowhere in the description does it say that this value is in seconds.

The description should say it all.

And when you have to go through some other articles, it's too bad.

Who told you that these are values in seconds?

 
Eugeni Neumoin :

There is a language description that says: Value can be one of the values of enumeration ENUM_TIMEFRAMES.

See further in the language description:

Graph periods

All predefined chart periods have unique identifiers. The PERIOD_CURRENT identifier denotes the current period of the chart, at which the mql5 program is running.

ENUM_TIMEFRAMES

Identifier

Description

PERIOD_CURRENT

Current period

PERIOD_M1

1 minute

PERIOD_M2

2 minutes

PERIOD_M3

3 minutes

PERIOD_M4

4 minutes

PERIOD_M5

5 minutes

PERIOD_M6

6 minutes

PERIOD_M10

10 minutes

PERIOD_M12

12 minutes

PERIOD_M15

15 minutes

PERIOD_M20

20 minutes

PERIOD_M30

30 minutes

PERIOD_H1

1 hour

PERIOD_H2

2 hours

PERIOD_H3

3 hours

PERIOD_H4

4 hours

PERIOD_H6

6 hours

PERIOD_H8

8 hours

PERIOD_H12

12 hours

PERIOD_D1

1 day

PERIOD_W1

1 week

PERIOD_MN1

1 month

======================

And nowhere in the description does it say that this value is in seconds.

The description should say it all.

And when you have to go through some other articles, that's too bad.

You should never rely on an enumeration value.

Use PeriodSeconds().