This code is straight from page (https://book.mql4.com/operators/switch) of the manual.
I am a little confused over the format of the line:
It normalizes the double up to a defined no. of digits..
also it should be
int Delta=NormalizeDouble((Bid-Level)/Point,0); // Excess
and to make that warning go away you should convert it to int
int Delta= (int)NormalizeDouble((Bid-Level)/Point,0); // Excess
It normalizes the double up to a defined no. of digits..
also it should be
and to make that warning go away you should convert it to int
Hi Lakshan,
This is an example taken directly from the manual. It's not a code that I've programmed myself, I am just trying to understand the functionality of this particular example.
This is exactly how the line is from the manual:
int Delta=NormalizeDouble((Bid-Level)Point,0); // Excess
So in the above example, would I be correct in saying that; 'Delta' is assigned with the point value of (Bid-Level) to 0 decimal places?
Or are you trying to say that the line does not make sense unless there is a division (/) in between (Bid-Level) and Point?
Thanks again.
Hi Lakshan,
This is an example taken directly from the manual. It's not a code that I've programmed myself, I am just trying to understand the functionality of this particular example.
This is exactly how the line is from the manual:
So in the above example, would I be correct in saying that; 'Delta' is assigned with the point value of (Bid-Level) to 0 decimal places?
Or are you trying to say that the line does not make sense unless there is a division (/) in between (Bid-Level) and Point?
Thanks again.
1) NormalizeDouble() with 0 digits, is a sort of rounding off to value without any decimal place(aka 0 digits after the decimal point) ==> integer (as mentioned above)
2) Also, if you try to compile the above code without the division operator(/) or any other operator for that matter, you will encounter an error.. 'Point' - some operator expected
1) NormalizeDouble() with 0 digits, is a sort of rounding off to value without any decimal place ==> integer (as mentioned above)
2) Also, if you try to compile the above code without the division operator(/) or any other operator(even though it is incorrect) you will encounter an error..
I'm not trying to compile this code... this is just an example from the manual. I am not going to be using this EA myself it is just simply an example from the manual of how a 'Switch' operator works, which happens to use that line within it.
I understand that NormalizeDouble() with 0 digits is rounding it off without a decimal place.
Are you saying that the following code:
int Delta=NormalizeDouble((Bid-Level)Point,0); // Excess
Does not make sense? As I've mentioned this is from the MQL5 Manual Tutorial so I doubt they would have left an incorrect example in there...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
But let's say that I put that division sign in there to make the code look like this:
int Delta=NormalizeDouble((Bid-Level)/Point,0); // Excess
Will that then divide the difference between the bid and level with the current point value?
And if so:
How is the point value displayed? If EUR/USD is trading exactly at 1.17002 then does this display 'point' as:
1.17002
or
2
Thanks again.
I'm not trying to compile this code... this is just an example from the manual. I am not going to be using this EA myself it is just simply an example from the manual of how a 'Switch' operator works, which happens to use that line within it.
I understand that NormalizeDouble() with 0 digits is rounding it off without a decimal place.
Are you saying that the following code:
Does not make sense? As I've mentioned this is from the MQL5 Manual Tutorial so I doubt they would have left an incorrect example in there...
Yes it is wrong without any operator..
But let's say that I put that division sign in there to make the code look like this:
Will that then divide the difference between the bid and level with the current point value?
And if so:
How is the point value displayed? If EUR/USD is trading exactly at 1.17002 then does this display 'point' as:
1.17002
or
2
Thanks again.
in your example value of Point is 0.00001
Yes it is wrong without any operator..
in your example value of Point is 0.00001
I think I understand what you are saying now.
So if I add the division sign to the example and we presume that EUR/USD is Bid at 1.3201, and 'Level' maintains the value of '1.3200':
int Delta= (int)NormalizeDouble((Bid-Level)/Point,0);
...then 'Delta' effectively assumes the value of 10 due to the calculation:
(1.3201-1.3200)/0.00001 = 10
Is this correct?
I think I understand what you are saying now.
So if I add the division sign to the example and we presume that EUR/USD is Bid at 1.3201:
...then 'Delta' effectively assumes the value of 10 due to the calculation:
Is this correct?
Yes exactly.. :-)
- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
int Delta= (int)NormalizeDouble((Bid-Level)/Point,0);is exactly (minus sub-point rounding,) the same as
int Delta= int((Bid-Level)/Point);
Youris exactly (minus sub-point rounding,) the same as
Thanks for the advice.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This code is straight from page (https://book.mql4.com/operators/switch) of the manual.
I am a little confused over the format of the line:
I understand that 'NormalizeDouble' is a rounding tool that is used to round a number to a specified amount of decimal places.
I understand that 'Point' or 'point value' or 'point size' is effectively a tenth of a pip.
I understand that the '0' represents the number of decimal places that 'NormalizeDouble' should round to.
But am I correct in saying that the mentioned line effectively assigns 'Delta' with the point value of (Bid-Level) to 0 decimal places? Or am I totally along the wrong lines?
----------------
e.g. if:
Bid=1.3201
and
Level=1.3200
then:
int Delta=10
----------------
Thanks for help in advance.