Using a macd indi and doubles I cannot parse

To add comments, please log in or register
Filmon Daniels
195
Filmon Daniels  

Hi, 

I have read a few threads regarding handling doubles and I can't say I understand. Please find the following links

article on working with doubles - https://www.mql5.com/en/articles/1561
a similar issue - https://www.mql5.com/en/forum/155049
why i shouldn't use NormalizeDouble https://www.mql5.com/en/forum/137301
the == operand - https://www.mql5.com/en/forum/145258
a valuable thread on this issue - https://www.mql5.com/en/forum/136997
using alternative double comparators - https://www.mql5.com/en/forum/139140https://www.mql5.com/en/forum/118953#comment_3150582

I am using the macd via iCustom and I am getting values like  -9.163163680847575e-05 which actually is equivalent to -0.00009163 using DoubleToStr.

Among other operations I need to check if it is greater than / less than 0. It's been a bit of a struggle. I haven't had much success with DoubleToStr as it converts it into a string. I would like to get the string value as a double and understand the limitations of the primitive type in mql4. Also have read about dlls and trying to use c++ libs for transformation and better precision but had no success in any of the above.

Another issue cut from a similar cloth is when 
you get these kind of values and using typical gt/lt it somehow returns true i.e. 0.000002341341 is less than 0 


I feel like all the clues are there but i'm blind to it, can anyone help.

Any help is appreciated

some code so i dont get bollocked 

double getMacd(int idx=0,int shift=0) { 
   return iCustom(_Symbol,_Period,"MASi_MACDHist.ex4",
      12,26,9,true,true,"",false,false,false,false,false,false,false,false,idx,shift);
}

int macdSignal() {
   static int macd_signal = 0;

   double current_macd = getMacd(0,0);
   double previous_macd = getMacd(0,1);
   
   double current_macd_signal = getMacd(1,0);
   double previous_macd_signal = getMacd(1,1);
      
   //macd lines are below 0 & crosses over
   if(previous_macd <= previous_macd_signal && current_macd > current_macd_signal) {
      if(previous_macd_signal < 0) { macd_signal = 1; }
   }
   
   //macd lines are above 0 & crosses under
   if(previous_macd >= previous_macd_signal && current_macd < current_macd_signal) {
      if(previous_macd_signal > 0) { macd_signal = -1; }
   }
      
   Print(
      "\ncurrent macd: " + DoubleToStr(current_macd) + " " + current_macd +
      "\ncurrent mac_sig: " + DoubleToStr(current_macd_signal) + " " + current_macd_signal
   );

   
   return macd_signal;
}
Working with Doubles in MQL4
Working with Doubles in MQL4
  • www.mql5.com
The MQL programming opens new opportunities for the automated trading, many people all over the world already have appreciated it. When we are writing an Expert Advisor for trading, we must be sure that it will work correctly. Many newbies often have some questions when the results of some mathematical calculations differ from those expected...
William Roeder
23253
William Roeder  

Filmon Daniels:

I am using the macd via iCustom and I am getting values like  -9.163163680847575e-05 which actually is equivalent to -0.00009163 using DoubleToStr.


Among other operations I need to check if it is greater than / less than 0. It's been a bit of a struggle.

You happen to be getting values near zero.

Why is if(v > 0) a struggle? You have confused yourself.

Only if you are comparing prices and equality is important do you need extra care.

Filmon Daniels
195
Filmon Daniels  
I think I might have. I am unable to recreate and, with added logging, proved that this is not an issue. The issue is probably with comparing between two non-zero doubles. I will read through code and forums again and debug. Thank you for your response.
To add comments, please log in or register