Incorrectly displaying the standard deviation figure despite correct formatting. [SOLVED - CORRECT CODE DISPLAYED]

 

Right, quite frankly, I have just about had enough of this..

I currently have a snippet of code which returns the standard deviation of a currency pair and displays this in an email which is subsequently sent.

The standard deviation is calculated in the #include file called: 

chart_objects_correl.mqh

The standard deviation is declared as a variable under:

double standardDeviation; 

& is calculated of the variable is as follows:

standardDeviation =  NormalizeDouble(sqrtEyMinusAveragePow2 / Point,2);

& so - depending on whether the JPY is present on the chart, an email is sent display the differing standard deviation limits.

int OnInit()
  {
  
      chart_objects();

      
      string strStandardDeviationNormal      =    StringFormat("Standard Deviation %0.0f Minimum: %0.0f Maximum: %0.0f",standardDeviation,minStandardDeviationHam, maxStandardDeviationHam);
      string strStandardDeviationVolatile    =    StringFormat("Standard Deviation %0.0f Minimum: %0.0f Maximum: %0.0f",standardDeviation,minStandardDeviationHamVol, maxStandardDeviationHamVol);       
      string present;
      int    isJPYPresent                    =    StringFind(Symbol(),"JPY",0);
      int    isGPBAUDPresent                 =    StringFind(Symbol(),"GBPAUD",0);
      bool   isCurrencyPresent               =    (isJPYPresent || isGPBAUDPresent >= 0);
      bool   isStandardDeviationNor;
      bool   isStandardDeviationVol;
      
      switch (isCurrencyPresent){
         
         case 0: //bool returns false
         
            isStandardDeviationNor  =  (standardDeviation >= minStandardDeviationHam && standardDeviation <= maxStandardDeviationHam);
            
               present = (isStandardDeviationNor ? "PASS | " : "FAIL  | ") + strStandardDeviationNormal;             
                  
                  PrintFormat(present);
                  
                     Print("Yen or GBPAUD is not present");
                  
                        break;
   
         case 1: //bool returns true.
                     
            isStandardDeviationVol  =  (standardDeviation >= minStandardDeviationHamVol && standardDeviation <= maxStandardDeviationHamVol);
   
               present = (isStandardDeviationVol ? "PASS | " : "FAIL  | ") + strStandardDeviationVolatile; 
               
                  PrintFormat(present);
                  
                     Print("Yen or GBPAUD is present");
                  
                        break;
            
         default:
         
               present = StringFormat("Unable to be determied. Please see error %d",GetLastError());
               
                  break;
      
      }
      
      SendMail("Present",present);
   
         
   return INIT_SUCCEEDED;
      
  } 

The standard deviation variable is a `double ' variable and so it's a floating variable, so it's correctly formatted.

Stick it on a chart, and guess what, I get a standard deviation of 0. Not the actual standard deviation, oh no - because that would be way too simple - I get "0". 

If I see an email with 0 as the standard deviation one more time, I will scream.

Why is it incorrectly displaying a standard deviation of zero.

Standard Deviation - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
Standard Deviation — value of the market volatility measurement. This indicator describes the range of price fluctuations relative to Moving...
 
TheHonestPrussian:

Right, quite frankly, I have just about had enough of this..

I currently have a snippet of code which returns the standard deviation of a currency pair and displays this in an email which is subsequently sent.

The standard deviation is calculated in the #include file called: 

The standard deviation is declared as a variable under:

& is calculated of the variable is as follows:

& so - depending on whether the JPY is present on the chart, an email is sent display the differing standard deviation limits.

The standard deviation variable is a `double ' variable and so it's a floating variable, so it's correctly formatted.

Stick it on a chart, and guess what, I get a standard deviation of 0. Not the actual standard deviation, oh no - because that would be way too simple - I get "0". 

If I see an email with 0 as the standard deviation one more time, I will scream.

Why is it incorrectly displaying a standard deviation of zero.

That is actually what you told StringFormat to do.

Your format specifies zero digits after the decimal point.


StringFormat("Standard Deviation %0.0f Min %0.0f Max %0.0f",standardDeviation, minStandardDeviationHamVol, maxStandardDeviationHamVol);

Change this:

StringFormat("Standard Deviation %f Min %f Max %f",standardDeviation, minStandardDeviationHamVol, maxStandardDeviationHamVol);  
               
 
Dominik Christian Egert #:
That is actually what you told StringFormat to do.

Your format specifies zero digits after the decimal point.



Change this:

Still getting a zero figure.



Still getting a zero figure.

 
TheHonestPrussian #:



Still getting a zero figure.

What is printed when adding this??

Print(sqrtEyMinusAveragePow2 / Point);
EDIT:

Maybe it would help you, if you step through your code with the debugger and track your values in the watch window.

This way you can find your issue.
 
Dominik Christian Egert #:
Print(sqrtEyMinusAveragePow2 / Point)

Saying 0


Print(sqrtEyMinusAveragePow2 / Point); 
2023.07.14 09:26:15.395 experimental EURAUD,H1: 0.0

This is despite this exact same code in another function which works perfectly, this is what's infuriating me. It's utter bullshit to be honest. 

 
TheHonestPrussian #:

Saying 0


This is despite this exact same code in another function which works perfectly, this is what's infuriating me. It's utter bullshit to be honest. 

use the debugger.

For some reason this is zero.

sqrtEyMinusAveragePow2

You know how to use the debugger?
 
Dominik Christian Egert #:
use the debugger.

For some reason this is zero.


You know how to use the debugger?

I do, yes, I'll debug this idiot. Thanks for your help on this anyway. 

 
Dominik Christian Egert #:
use the debugger.

For some reason this is zero.


You know how to use the debugger?

Right, there is an ongoing issue with Metquotes software which may or may not have been reported:

This:

present = isStandardDeviationNor ? "PASS | " : "FAIL  | " + StringFormat("Standard Deviation %f Min %f Max %f", standardDeviation, minStandardDeviationHam, maxStandardDeviationHam);              

is resulting in this:

How absolutely stupid is this? Completely ignoring a key element of the code. I have been coding for 10 years and I have never come across such stupidity as I am today. How do you report bugs to Metaquotes? 

Furthermore, just to prove my point:


present = isStandardDeviationNor ? "PASS | " : "FAIL  | " + "You should be able to see this text.";  

is still returning:

 
TheHonestPrussian #:

Right, there is an ongoing issue with Metquotes software which may or may not have been reported:

This:

is resulting in this:

How absolutely stupid is this? Completely ignoring a key element of the code. I have been coding for 10 years and I have never come across such stupidity as I am today. How do you report bugs to Metaquotes? 

Furthermore, just to prove my point:


is still returning:

No, I am confident, it's a bug in your code.

Believe it or not. But once resolved, you will see it was actually a bug in your code.

Print out all values along the way, maybe use this library to help you debug the code:


(Not especially for beginners)

And use the debugger.
 
present = isStandardDeviationNor ? "PASS | " : "FAIL  | " + "You should be able to see this text.";  

Ternary operator definition:  expression? expression: expression3

Yellow background is expression printed when true, red background when false.

If you want to append last string to the result of the ternary operator, then use round brackets:


present = ( isStandardDeviationNor ? "PASS | " : "FAIL  | "  ) + "You should be able to see this text.";  
 
Dominik Christian Egert #:
No, I am confident, it's a bug in your code.

Believe it or not. But once resolved, you will see it was actually a bug in your code.

Print out all values along the way, maybe use this library to help you debug the code:


(Not especially for beginners)

And use the debugger.

Thank you for your time. All the best :)