
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hexadecimal logic is the same everywhere. You can read about number systems here. There you can read about positional number systems and see references to 16 and binary. There are more examples of conversion from system to system there.
All bitwise operations are intended for the binary system. About bitwise operations in MQL5 here.
These articles are good to read when you already know what you are talking about :)
For example, you use the prefix "0x" in the enumeration. As far as I understand, it means that hexadecimal numbers are written, while the expression "(flag_event & CHARTEVENT_NEWBAR_M1)!=0" uses "bitwise AND operation". You write that bitwise operations are intended for the binary system. Then how does the & operator (for binary system) relate to hexadecimal numbers?
Another question: If I understood correctly, the expression "(flag_event & CHARTEVENT_NEWBAR_M1)!=0" is equivalent to the expression"flag_event !"= CHARTEVENT_NEWBAR_M1". Is that right? And if so, why use bitwise operations?
Вы же пишите, что побитовые операции предназначены для двоичной системы
What's the difference? The numbers inside the CPU are binary anyway.
so even if you "see" 255 or FF in your head and compare it with 8 or with 0x00000100 there will be no difference.
Another question. If I understood correctly, the expression "(flag_event & CHARTEVENT_NEWBAR_M1)!=0" is equivalent to the expression"flag_event !"= CHARTEVENT_NEWBAR_M1". Is that right? And if so, why use bitwise operations?
What's the difference? The numbers inside the CPU are binary anyway.
so even if you "see" 255 or FF in your head and compare it with 8 or with 0x00000100 there will be no difference.
The difference is terminological. But I understood from your words that it doesn't matter for programmers.
yes, in this situation it means exactly that, but bit operations are wider in application and more general than just comparison, especially since it has already become a classical behaviour to use bit operations when working with constants.
I see! So, if I am a bit unfamiliar with bit operations, I can safely rewrite expressions using comparison operators? Thank you for the clarification!
These articles are good to read when you already know what it's about :)
For example, you use the prefix "0x" in your enumeration. As far as I understand, it means that hexadecimal numbers are written, while the expression "(flag_event & CHARTEVENT_NEWBAR_M1)!=0" uses the"bitwise AND operation". You write that bitwise operations are intended for the binary system. Then how does the & operator (for binary system) relate to hexadecimal numbers?
All these systems just visually represent numbers in a different way, and so if a number is ten, it's ten everywhere. For the comp, ALL numbers, no matter what system we write them in, are converted to binary. Even these letters that I write are converted to binary. In other systems, numbers are labelled mainly to improve clarity or out of habit. Well, some people do it to look smarter. In this case, hexadecimal numbers were used for compactness of writing, well, and for better clarity. Visibility comes when you know how hexadecimal numbers are formed.
Another question: If I understood correctly, the expression "(flag_event & CHARTEVENT_NEWBAR_M1)!=0" is equivalent to the expression"flag_event !"= CHARTEVENT_NEWBAR_M1". Is that right? And if so, why use bitwise operations?
No, this is not always the case. It would depend on what was written in flag_event. If only CHARTEVENT_NEWBAR_M1 was written to flag_event, then flag_event = CHARTEVENT_NEWBAR_M1. IfCHARTEVENT_NEWBAR_M1|CHARTEVENT_NEWBAR_M5waswritten toflag_event , then flag_event != CHARTEVENT_NEWBAR_M1.But in both cases the condition (flag_event & CHARTEVENT_NEWBAR_M1)!=0will be fulfilled .
If youwrite CHARTEVENT_NEWBAR_M5 in flag_event , then flag_event != CHARTEVENT_NEWBAR_M1. But (flag_event & CHARTEVENT_NEWBAR_M1)=0.
To understand these tricks, you need to understand number systems and bitwise operations. Otherwise, you will be dead.
I see! I.e. if it is a bit unusual for me to use bitwise operations, I can safely rewrite expressions using comparison operators? Thank you for the clarification!
You can always replace it, but it may require additional calculations. Be careful with this case :).
Ok! One more question. When writing hexadecimal numbers, you use the degree of two. Is there any sense in using degrees of two or is it also a matter of habit? I.e. could such combinations be used: 0x00000003, 0x00000009, etc.?
Okay! One more question. When writing hexadecimal numbers, you use degrees of two. Is there any sense in using degrees of two or is it also a matter of habit? I.e. could such combinations be used: 0x00000003, 0x00000009, etc.?
No. This is due to the use of bitwise operations. In the spy I add several numbers (events) into one number (in flag_event), and in the EA I take out several numbers from one number to see what events the spy sent. And vice versa.
Oh, didn't read that carefully. Yes, you could, except I probably wouldn't have enough one number to fit all the events. The degree two is used because I'm working with a binary representation of the number, and writing in hexadecimal. Each bit represents a different event.
By default, price[rates_total-1] is equal to the close price of the last unfinished bar, which in turn is equal to the last bid price. i.e. we always get the bid price from the spy by default.
If you want to get the ask price by force, replace this line, for example, with the following.
Author, I'm sorry, maybe I didn't finish reading, but can this function pass to the Expert Advisor not only price events, but, for example,
events of an indicator or their combinations/variations from other instruments, i.e. as if the signal already received there. If yes, how to implement it.
Thank you for your reply.
By default, price[rates_total-1] is equal to the close price of the last unfinished bar, which, in turn, is equal to the last bid price. i.e. we always get the bid price from the spy by default.
If you want to forcibly get the ask price, replace this line, for example, with the following.
Author, I'm sorry, maybe I didn't finish reading, but can this function pass to the Expert Advisor not only price events, but, for example,
events of an indicator or their combinations/variations from other instruments, i.e. as if the signal already received there. If yes, how to implement it.
Thank you for the answer.