Name of variable causing Divide by Zero

 

I ran into something of a bug while writing some code to round spread data to the nearest multiple of my choice. See below:

//Given that (in the variable declaration):
//extern double DMultiple4 = 2;

if(SignalID == 4)
{
   RefreshRates();
   D = ((Ask-Bid)*100000); Print("DMultiple4 is "+DMultiple4);
   data = MathRound(D/DMultiple4)*DMultiple4;
}

return(data);

Nowhere else in the code have I manipulated the variable DMultiple4. These are the only references to DMultiple4. The print returns that DMultiple4 is 0.00000000!

So I change the name of the variable to "Something". And it works without a problem. I even made the replacement using the "Replace all" command. The print will return Something is 2.00000000.

If I change it back again to DMultiple4, DMultiple4 is 0.00000000. Why is this happening? I have no explanation.

 
Hiltos:


If I change it back again to DMultiple4, DMultiple4 is 0.00000000. Why is this happening? I have no explanation.

You missed one change . . .
 
I wish that were the case. Just to make sure I'm using Find and Replace. There are only 3 times this variable are used in the program (excluding the print function.)
 

Ok, so I tried a little experiment. I had the variable named DMultiple4. and the Divide by Zero error was there.

So without changing anything else, I saved another copy of my EA with a slightly different name. I compiled the new saved copy and tried it. No divide by zero! Does the compiler use cached data of any kind?

 
Hiltos: If I change it back again to DMultiple4, DMultiple4 is 0.00000000. Why is this happening? I have no explanation.
You have it declared as an external/global AND a local. The local hides the global.
 

Hi WHRoeder!

I have the variable declared as an external in the global scope. The notes in the code that I posted aren't really in the program. I just wanted to show how it was being declared on the global scope. It's not actually re-declared locally in the function. Here's the entire function:

// --------------------------- //
double GetSigData(int SignalID, int TimeofP)
  {
   double data, D;
   if(TimeofP == 0){TimeofP = 1;}
   
   if(SignalID == 0)
      {
      D = iRSI(NULL,SubTime,RSIPeriod,RSIApplied,TimeofP);
      data = MathRound(D/DMultiple0)*DMultiple0;
      }
   
   if(SignalID == 1)
      {
      D = iDeMarker(NULL,SubTime,DEMPeriod,TimeofP)*100;
      data = MathRound(D/DMultiple1)*DMultiple1;
      }
   
   if(SignalID == 2)
      {
      D = iStdDev(NULL,SubTime,STDPeriod,0,1,4,TimeofP);
      data = MathRound(D/DMultiple2)*DMultiple2;
      }
   
   if(SignalID == 3)
      {
      D = iCCI(NULL,SubTime,CCIPeriod,CCIApplied,TimeofP);
      data = MathRound(D/DMultiple3)*DMultiple3;
      }
   
   if(SignalID == 4)
      {
      RefreshRates();
      D = ((Ask-Bid)*100000); Print("DMultiple4 is "+DMultiple4);
      data = MathRound(D/DMultiple4)*DMultiple4;
      }
      
   if(SignalID == 5)
      {
      D = Volume[TimeofP];
      data = MathRound(D/DMultiple5)*DMultiple5;
      }
      
   return(data);
  }

Also, The other DMultiple# variables didn't have this issue.

 
Show the code where you set the values. Showing half the code is useless.
 
//+------------------------------------------------------------------+
//| Variable Declaration
//+------------------------------------------------------------------+

// External Variables
extern int     Lean =            25;
extern int     MaxSpread =       20;
extern double  DMultiple0 =      1;
extern int     RSIPeriod =       14;
extern int     RSIApplied =      4;

extern double  DMultiple1 =      1;
extern int     DEMPeriod =       14;

extern double  DMultiple2 =      0.002;
extern int     STDPeriod =       89;

extern double  DMultiple3 =      1;
extern int     CCIPeriod =       14;
extern int     CCIApplied =      4;

extern double  DMultiple4 =      2;
//             This one is spread (in Points).

extern double  DMultiple5 =      500;
//             Signal5 is Volume[TimeofP].

Here are all the external declarations.

 
Hiltos:

Here are all the external declarations.

Please post your complete code so what you are alleging can be reproduced and investigated.
Reason: