How do I go through an enumeration consistently? - page 5

 
Sergei Vladimirov:
Why would I do that?
TickSize on MIX is 25, Digits is 0. Normalising an integer price that is not a multiple of 25 will cause an OrderSend error.
 
fxsaber:
TickSize on MIX is 25 and Digits is 0. Normalising an integer price that is not a multiple of 25 will cause an OrderSend error.
Just now in a neighbouring thread advised to drown the computer in the bathtub, then everything will be discredited even more.
 
Dmitry Fedoseev:
Just now in a neighbouring thread advising to drown the computer in the bathtub, then everything will be discredited even more.
You're a blabbermouth, unfortunately. I don't create anything, but I have the right to criticise - about you.
 
fxsaber:
TickSize on MIX is 25 and Digits is 0. Normalising an integer price that is not a multiple of 25 will cause an OrderSend error.
Well, with that logic even in a 0.25 step normalisation would produce an error. The purpose of normalization is not to adjust the price to some exotic price step, but to round the floating point number to a given accuracy. It does not cause any errors.
 
Sergei Vladimirov:
Well, with that logic even in the case of a 0.25 step, normalisation would produce an error. The purpose of normalisation is not to adjust the price to some exotic price step, but to round the floating point number to a given accuracy. It does not lead to any errors.
Normalisation was originally introduced for only one thing (and it is mentioned in the help) - trading functions.
 
Vladimir Batrudinov:

There are probably two functions that need to be entered: 1 - returns the number of elements in the enum, 2 - returns the element by number...


In enum, you can assign any values to the elements, for example, as below. An enum is not an array.

enum crazy
{
    e1 = 100500,
    e2 = -200,
    e3 = -100500,
    e4 = 0
};


//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
    int z10 = e2;
    int z1 = e4;
  
}

Languages like C# require to specify the enum name, while C++ and hence MQL4/5 handle enum rather freely. Just in case, this nonsense compiles on MQL5 as well as on C++

 
Alexey Volchanskiy:

In enum, you can assign any value to the elements, such as the following. enum is not an array.

So what? It was about going through the elements in declaration order.
 
Alexey Navoykov:
So what? It was about going through those elements in order of declaration.
Oh, right, I read the question wrong, I thought, by values.
 

A note to programmers:

#define  ENUM_QQ             \
  ENUM_QQ_HELPER(el_1, 3)   \
  ENUM_QQ_HELPER(el_2, 9)   \
  ENUM_QQ_HELPER(el_3, 38)  \
  ENUM_QQ_HELPER(el_4, 1)   

enum Enum_qq
{
#define  ENUM_QQ_HELPER(el, val) el = val,
  ENUM_QQ
#undef  ENUM_QQ_HELPER
};

void get_enumqq_array(int &ar[])
{
  int temp[] = {
#define  ENUM_QQ_HELPER(el, val) el,
  ENUM_QQ
#undef  ENUM_QQ_HELPER
  };
  ArrayResize(ar, ArraySize(temp));
  for(int i = 0;  i < ArraySize(temp);  ++i)
    ar[i] = temp[i];
}

void OnStart()
{
  int q[];
  get_enumqq_array(q);
  for(int i = 0;  i < ArraySize(q);  ++i)
    Alert(q[i]);
}


Now if we need to edit an enumeration, we have to edit it once and in one place. We need to add a new element, for example element_new = 56, we add

ENUM_QQ_HELPER(element_new , 56)

And don't bother editing get_enumqq_array(). The technique is called X Macro https://en.wikipedia.org/wiki/X_Macro. If developers wish, they can easily modify standard enumeration in this way.

Maybe not immediately obvious, the enumeration turned out this way:

enum Enum_qq
{
   el_1 = 3
   el_2 = 9
   el_3 = 38
   el_4 = 1   
};
 
Vasiliy Sokolov:

Let's say we have an enumeration. How can we get all possible values of this enumeration one by one, e.g. in a loop?

I.e. tf1++ must sequentially return PERIOD_M1, PERIOD_M2, PERIOD_M5... I think this cannot be done with the language tools.

But if there is an ENUM_MYENUM, the (ENUM_MYENUM)INT_MAX should give the maximum value of the enum. Otherwise this is a type conversion bug. It is just because the type conversion operator must return the value of this very type. Not necessarily valid in context, but valid for type.