Question to the MQL4 masters. Again about Double Compare. - page 3

 
komposter:

And in simplified form, it works as fast as ComparePrice:
But not as accurate :)
If the values differ by Point, it will give false results half the time.

And what has simplified mode got to do with it anyway? ComparePrice in simplified form can be as slow as unsimplified equal.
 
Irtron:
Integer:

First, write a few Expert Advisors on your own order, feel the storm of a customer that suddenly the stop-loss was 1 point wrong... And then explain them about absurdity of NormalizeDouble() function, I wonder how it will work out for you=)

Let me tell you a secret.
I have written many more custom Expert Advisors than needed to start with. I have never felt the urge to buy them because I have never gave any reason to do so. In my programs, the stoploss is guaranteed to be (and not "appears") where it should be. Accordingly, I don't have to explain anything of the kind to the customer, especially about some very specific function. It seems to me that the whole point of writing an EA is to get rid of such questions and explanations for the client.

And how can it be reliably located where it should be without the NormalizeDouble() function? And how do you free yourself from explanations without using NormalizeDouble()?
 
Irtron:
VBAG:
And it turns out that even the price taken from the server from your order still needs to be normalised!!!
That's unlikely. The MT guts are almost beyond normalized.
There were and are a lot of talks about incomprehensible performance of the Expert Advisor when tested on incomprehensible historical data.
Exactly, there was an incorrect story, I remember. But it was the lack of normalize that was critical for the tester. Whatever.
And how do you deal with indicator dubs when comparing to 0 etc without normalise. Very interesting.
 
VBAG:
And how do you deal with indicator dubs when comparing to 0 etc. without normalise. Very interesting.
You won't believe it :)
    double cci;
    
    cci = iCCI(NULL, 0, 14, PRICE_CLOSE, 1);
    
    if (cci > 0.)
        Print("Above");
    else if (cci < 0.)
        Print("Below");
    else
        Print("Bingo!");
 
Irtron:
VBAG:
And how do you deal with indicator dubs when comparing to 0 etc. without normalise. Very interesting.
You won't believe it :)
    double cci;
    
    cci = iCCI(NULL, 0, 14, PRICE_CLOSE, 1);
    
    if (cci > 0.)
        Print("Above");
    else if (cci < 0.)
        Print("Below");
    else
        Print("Bingo!");
Yeah, well... - that's understandable. I understood your approach, that in each specific situation the simplest solution is sought.


 
VBAG look at this script
int start()
  {
//----
string str;
bool ok1,ok2;
   for(int i=0;i<10;i++){
      double NotNormPrice_1=StrToDouble("1.1111"+i);
         for(int j=0;j<10;j++){
            double NotNormPrice_2=StrToDouble("1.1111"+j);
               if(NormalizeDouble(NotNormPrice_1,4)==NormalizeDouble(NotNormPrice_2,4)){
                  str="Metod 1: "+DoubleToStr(NotNormPrice_1,5)+" = "+DoubleToStr(NotNormPrice_2,5)+" ";
                  ok1=true;
               }                 
               else{
                  str="Metod 1: "+DoubleToStr(NotNormPrice_1,5)+" != "+DoubleToStr(NotNormPrice_2,5)+" ";
                  ok1=false;
               }
               if(NormalizeDouble(NotNormPrice_1-NotNormPrice_2,4)==0.0){
                  str=str+"Metod 2: "+DoubleToStr(NotNormPrice_1,5)+" = "+DoubleToStr(NotNormPrice_2,5);
                  ok2=true;
               }         
               else{
                  str=str+"Metod 2: "+DoubleToStr(NotNormPrice_1,5)+" != "+DoubleToStr(NotNormPrice_2,5);                
                  ok2=false;
               }
            if(ok1!=ok2)Print(str);
         }
   }
//----
   return(0);
  }

and the results of his work

09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11111 != 1.11115 Metod 2: 1.11111 = 1.11115
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11111 != 1.11116 Metod 2: 1.11111 = 1.11116
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11112 != 1.11115 Metod 2: 1.11112 = 1.11115
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11112 != 1.11116 Metod 2: 1.11112 = 1.11116
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11112 != 1.11117 Metod 2: 1.11112 = 1.11117
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11113 != 1.11115 Metod 2: 1.11113 = 1.11115
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11113 != 1.11116 Metod 2: 1.11113 = 1.11116
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11113 != 1.11117 Metod 2: 1.11113 = 1.11117
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11114 != 1.11115 Metod 2: 1.11114 = 1.11115
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11114 != 1.11116 Metod 2: 1.11114 = 1.11116
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11114 != 1.11117 Metod 2: 1.11114 = 1.11117
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11114 != 1.11118 Metod 2: 1.11114 = 1.11118
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11114 != 1.11119 Metod 2: 1.11114 = 1.11119
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11115 != 1.11111 Metod 2: 1.11115 = 1.11111
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11115 != 1.11112 Metod 2: 1.11115 = 1.11112
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11115 != 1.11113 Metod 2: 1.11115 = 1.11113
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11115 != 1.11114 Metod 2: 1.11115 = 1.11114
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11116 != 1.11111 Metod 2: 1.11116 = 1.11111
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11116 != 1.11112 Metod 2: 1.11116 = 1.11112
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11116 != 1.11113 Metod 2: 1.11116 = 1.11113
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11116 != 1.11114 Metod 2: 1.11116 = 1.11114
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11117 != 1.11112 Metod 2: 1.11117 = 1.11112
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11117 != 1.11113 Metod 2: 1.11117 = 1.11113
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11117 != 1.11114 Metod 2: 1.11117 = 1.11114
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11118 != 1.11114 Metod 2: 1.11118 = 1.11114
09:04:13 NormExperiment EURUSD,M5: Metod 1: 1.11119 != 1.11114 Metod 2: 1.11119 = 1.11114

Decide for yourself which arithmetic you prefer.

When determining the crossing of the indicator line (for example MA) with the price (of the type Price_Now>MA_Now and Previous_Price<=Previous_MA), you must always normalize to 8 digits.

 
Integer:

it is mandatory to normalise to 8 digits.


No, why down to 8? :) There's also a 7, 9, or 6. Some people go for 4.
Really, why an 8? What are the criteria?
 
VBAG:
I understand your approach to look for the simplest solution in each situation.

Correction. The most suitable and, if possible, effective one. Unfortunately, it is not always the easiest one.
 
Irtron:
Integer:

it is mandatory to normalise to 8 digits.


No, why up to 8? :) There's also a 7, 9, or 6. Some people go for 4.
Really, why an 8? What are the criteria?

Suppose

price = 1.1111

ma = 1.11110001

If you normalize to 8 digits, ma>price is correct. Normalizing to a lower number of digits will make them equal - incorrect. This way maximum accuracy is achieved.

Normalizing to 9 digits does not work. It is as if the price has 9 digits and the indictor has 8 or vice versa (I don't remember), in short it is covered by the mystery of the unknown.

 
Irtron:

    double cci;
    
    cci = iCCI(NULL, 0, 14, PRICE_CLOSE, 1);
    
    if (cci > 0.)
        Print("Above");
    else if (cci < 0.)
        Print("Below");
    else
        Print("Bingo!");

This method passes. So far, no one has noticed the resulting margin of error.)