Understanding an Expression

 

Hey guys, 

can anyone please explain me what this expression means and how the (!=) condition is being evaluated? 

(m_patterns_usage&(((int)1)<<p))!=0

For more context, this code is part of a macro which is defined in the ExpertSignal.mqh after generating an Expert using a moving average as signal. 

ExpertSignal.mqh:

#define IS_PATTERN_USAGE(p)          ((m_patterns_usage&(((int)1)<<p))!=0)

my question is not about how the signal module/system is working but about the language implementation and how the syntax works in this scenario and

to be more precise:

  1. What "&" symbol means? is this a logical operator or its a reference to the "m_patterns_usage" property? 
  2. What does "((int)1)" means?

Thank you!


Cheers, 

Zarik

Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 

Forum on trading, automated trading systems and testing trading strategies

Understanding an Expression

Zarik, 2022.07.26 15:42

can anyone please explain me what this expression means and how the (!=) condition is being evaluated? 

(m_patterns_usage&(((int)1)<<p))!=0

Checking if the p-th bit is non-zero in the binary representation of the number m_patterns_usage.

 
Zarik: can anyone please explain me what this expression means and how the (!=) condition is being evaluated? For more context, this code is part of a macro which is defined in the ExpertSignal.mqh after generating an Expert using a moving average as signal. to be more precise:

  1. What "&" symbol means? is this a logical operator or its a reference to the "m_patterns_usage" property? 
  2. What does "((int)1)" means?

Please take the time to read the documentation and familiarise yourself with operators and expressions: Documentation on MQL5: Language Basics / Operations and Expressions

Bitwise Operations

Left Shift (<<)

The binary representation of x is shifted to the left by y digits, the freed right-side digits are filled with zeros.

Bitwise AND Operation (&)

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

Operations of Relation

a != b; //  True if a is not equal to b                  

Boolean Operations

Logical Negation NOT (!)

Operand of the logical negation (!) must be of arithmetic type. The result is TRUE (1), if the operand value is FALSE (0); and it is equal to FALSE (0), if the operand differs from FALSE (0).

Typecasting

(int)


 
Fernando Carreiro #:

Please take the time to read the documentation and familiarise yourself with operators and expressions: Documentation on MQL5: Language Basics / Operations and Expressions

Bitwise Operations

Left Shift (<<)

The binary representation of x is shifted to the left by y digits, the freed right-side digits are filled with zeros.

Bitwise AND Operation (&)

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

Operations of Relation

a != b; //  True if a is not equal to b                  

Boolean Operations

Logical Negation NOT (!)

Operand of the logical negation (!) must be of arithmetic type. The result is TRUE (1), if the operand value is FALSE (0); and it is equal to FALSE (0), if the operand differs from FALSE (0).

Typecasting

(int)


That was where my Problem laying! The Typecasting! Thank you very much!

Cheers, 
Zarik

Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Typecasting - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
fxsaber #:

Checking if the p-th bit is non-zero in the binary representation of the number m_patterns_usage.

Blees You! 


Cheers,

Zarik

Reason: