unknown what your code for ratio declaration or Print() o/p actually is so...
as an idea to consider:
.
is ratio type double?
if so, what if ratio is 3.00001234 ?
because your Print(ratio) is guaranteed to display "3.0000"
please read editor docs on Print()
hth
Thanks for your help but the problem is not the print function but that the function is executed
for information "double" ratio = "double" 0.3 / "double" 0.1
The result is "double" 3 but the function ignore it!
Thanks for your help but the problem is not the print function but that the function is executed
for information "double" ratio = "double" 0.3 / "double" 0.1
The result is "double" 3 but the function ignore it!
i currently don't have time to do the math, but there is no guaratee that 0.3/0.1 is exactly 3.
there is some article here on mql4 how to work with double values...
//edit: here it is https://www.mql5.com/en/articles/1561
edit: just seen zzeugg's reply and it kinda sums up the issue
.
if (CalculateCurrentOrders(Symbol())==2 && ratio!=3) { Print("inside "," current orders : ",CalculateCurrentOrders(Symbol())," ratio: ",ratio); // i have deleted ordersend to simplify it }
without disrupting your coding too much, I did below. It might help. suggest you search site, there are long threads on this double stuff...
I cannot locate refs at moment, but double comparisons is seen by some to be loaded with troubles. Is about what a double is and how it is stored etc.
Others just use the normal relational operators and 'get away with it'. I personally have set of functions with name convention of:
bool isAgeB(),isAgtB(),isAeqB(),isAneB(),isAltB(),isAleB() and each have 2 double formals. using syntax like: {return( NormalizeDouble( P1 - P2, Digits ) != 0 );}
altered according to relational test needed
overkill? well, let's just say my uneducated response to all the debate was to make above and run with it. Much smarter folk than me have debated much and as such something must be at issue, but I am not going to spend energies in attempts to understand - am not maths sort of person...
.
Anyway, this is why NormalizeDouble () is very important to take on board. The lack of using it with trade order actuals often gives one errors on return from call.
Please view this: https://docs.mql4.com/basis/operations/relation (**)
//+------------------------------------------------------------------+ //| ^TEST_HARNES.mq4 | //| | //| | //+------------------------------------------------------------------+ #property show_inputs #include <WinUser32.mqh> #include <stdlib.mqh> #include <stderror.mqh> extern double edDivisor = 0.1; int start() { double dRatio; dRatio = NormalizeDouble(0.3/edDivisor,2); //<<<<<<<<--------- without NormalizeDouble() the 'questionable' if always gets inside Print("Before if condition \"&& ratio!=3\": ",DoubleToStr(dRatio,8)); if(iCalculateCurrentOrders(Symbol())==2 && dRatio!=3.00) //<<<<<<<<<<--------- this works but not follow link (**) { Print("inside "," current orders : ",iCalculateCurrentOrders(Symbol())," ratio: ",dRatio); } else Print("outside "," current orders : ",iCalculateCurrentOrders(Symbol())," ratio: ",dRatio); return(0); } int iCalculateCurrentOrders(string sSym) { return(2); } /* 2010.07.30 12:01:19 ^TEST_HARNES EURUSD,M15: inside current orders : 2 ratio: 2.43 2010.07.30 12:01:19 ^TEST_HARNES EURUSD,M15: Before if condition "&& ratio!=3": 2.43000000 2010.07.30 12:01:18 ^TEST_HARNES EURUSD,M15 inputs: dDivisor=0.12345; 2010.07.30 12:01:06 ^TEST_HARNES EURUSD,M15: loaded successfully 2010.07.30 12:00:32 ^TEST_HARNES EURUSD,M15: removed 2010.07.30 12:00:32 ^TEST_HARNES EURUSD,M15: uninit reason 0 2010.07.30 12:00:32 ^TEST_HARNES EURUSD,M15: outside current orders : 2 ratio: 3 2010.07.30 12:00:32 ^TEST_HARNES EURUSD,M15: Before if condition "&& ratio!=3": 3.00000000 2010.07.30 12:00:32 ^TEST_HARNES EURUSD,M15 inputs: dDivisor=0.1; */
but there is no guaratee that 0.3/0.1 is exactly 3.
I put NormalizeDouble(Double,1) everywhere and it works!!!!!!!!!!!!!!!!
many many thanks!
TAAD, how cool!
Congratulations on one job well done...
now for next and the next... ;-)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In my EA, i have the following code
Print is equal to : current orders : 2 (which is correct), ratio: 3 (which make me crazy)How it is possible that the print function return a ratio equal to 3 whereas one condition on the "if" is ratio must be different to 3 ???
What's wrong in my code ?
I loosed 4 hours to resolve it, i start to because totaly crazy! Thanks in advance for your help.
TAAD