returns the execution policy. - page 2

 
Vladimir Karputov:

Example from CTrade trade class. First it is checked for'SYMBOL_FILLING_FOK', then for'SYMBOL_FILLING_IOC'.


The check is performed by usingthe 'AND bitwise operation'.

Bitwise AND operation

The bitwise AND operation of the binary representations x and y. The value of the expression contains 1 (TRUE) in all bits where both x and y contain non-zero; and 0 (FALSE) in all other bits.


Example:


More about bitwise operations.

So by this code the execution policy is either ioc or fok or neither of them, so it turns out that there can't be two at the same time? Or did I misunderstand again?
 
Can't there be two at the same time after all? What does the function have to return for there to be two at the same time?
 
I must have misunderstood your answer. You meant in general, not in relation to one trading account. Thanks for your help.
 
Ivan_Invanov:
Can't there be two at the same time after all? What should the function return for there to be two at the same time?
It can be 2, then the function will return 3. BUT¡¡¡¡¡ This is an atypical situation. Given that there are only 3 options, it could be 1, 2 or the sum of 1+2. It is the sum, not the third option. So checking with a bitwise operation can only answer the question: Can this or that fill policy be applied.
 
Ivan_Invanov:
Can't there be two at the same time after all? What should the function return for there to be two at the same time?

Example of checks for two characters from the MetaQuotes-Demo server:

2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        MetaQuotes-Demo
2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        Fill or Kill, SYMBOL_FILLING_FOK: false
2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        Immediate or Cancel, SYMBOL_FILLING_IOC: true
2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        Return: true
2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        Flags of allowed order filling modes: SYMBOL_TRADE_EXECUTION_INSTANT
2020.07.19 07:35:07.922 Info_FILLING (USDRUB,H1)        
2020.07.19 07:35:45.291 Info_FILLING (EURUSD,H1)        MetaQuotes-Demo
2020.07.19 07:35:45.291 Info_FILLING (EURUSD,H1)        Fill or Kill, SYMBOL_FILLING_FOK: true
2020.07.19 07:35:45.291 Info_FILLING (EURUSD,H1)        Immediate or Cancel, SYMBOL_FILLING_IOC: false
2020.07.19 07:35:45.291 Info_FILLING (EURUSD,H1)        Return: true
2020.07.19 07:35:45.291 Info_FILLING (EURUSD,H1)        Flags of allowed order filling modes: SYMBOL_TRADE_EXECUTION_INSTANT

See the specifications (fill-in) for these symbols:



and here is a more common variant: when all fills are available for a symbol

2020.07.19 07:40:22.818 Info_FILLING (NZDUSD,H1)        MetaQuotes-Demo
2020.07.19 07:40:22.818 Info_FILLING (NZDUSD,H1)        Fill or Kill, SYMBOL_FILLING_FOK: true
2020.07.19 07:40:22.818 Info_FILLING (NZDUSD,H1)        Immediate or Cancel, SYMBOL_FILLING_IOC: true
2020.07.19 07:40:22.818 Info_FILLING (NZDUSD,H1)        Return: true
2020.07.19 07:40:22.818 Info_FILLING (NZDUSD,H1)        Flags of allowed order filling modes: SYMBOL_TRADE_EXECUTION_INSTANT

and specification


 
Thank you.
 
Alexey Viktorov:
It could be 2, then the function will return 3. BUT¡¡¡¡¡ This is an atypical situation. Given that there are only 3 options, it could be 1, 2 or the sum of 1+2. It is the sum, not the third option. So checking with a bitwise operation can only answer the question: Can this or that fill policy be applied.
still don't understand how one variable can return two terms. And if it returns a value of 3 as one member, bitwise operations won't work. I decided to just choose EXECUTION_INSTANT mode and I will always have a FOK policy .
 
Ivan_Invanov:
I still don't understand how one variable can return two members. And if it returns one term as 3, then bitwise operations won't work. I decided to just choose EXECUTION_INSTANT mode and I will always have a FOK policy .

To understand this you need to understand what flags are.

Each next value of a flag is the value of the previous one multiplied by 2. I.e. 1, 2, 4, 8, 16, 32......... So if the value is 33 it means that this value contains only 1 and 32. Similarly if the value is 18 it can only be composed of 16 and 2. And the value 3 can only be composed of 1 and 2.

So bitwise operations are just checking if the checked value is present in the sum of flags. If you check if an arbitrary number is included in 18 you get false, except for checking values 2 and 16.

 
Alexey Viktorov:

To understand this you need to understand what flags are.

Each next value of a flag is the value of the previous one multiplied by 2. I.e. 1, 2, 4, 8, 16, 32......... So if the value is 33 it means that this value contains only 1 and 32. Similarly if the value is 18 it can only be composed of 16 and 2. And the value 3 can only be composed of 1 and 2.

So bitwise operations are just checking if the checked value is present in the sum of flags. If you check if an arbitrary number is included in 18 you'll get false except for checking values 2 and 16.

Yes, I understand how to work with binary digits.

   uint filling=(uint)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
   if((filling&SYMBOL_FILLING_FOK)==SYMBOL_FILLING_FOK)
     {
      m_type_filling=ORDER_FILLING_FOK;

From this code, for example, the function returns 3 .

(11&1)==1 ; 11==01 no, that's false, it didn't work.

I was just writing this and thought maybe I misunderstood the operations.

& it means I convert decimal values to binary and do a bitwise conjunction.

== true when the first term is equal to the second term. Is this correct?

 
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh, it's finally getting there. If there is a value in a digit, it's a true flag and the triplet puts the value in both digits. Only why does this code work then?