Pulling my hair out over MathArctan2 -- Help!

 

Obviously, I'm doing something wrong, but I can't see it for the life of me. 

I'm testing against AUDUSD on a 5-minute chart.


(FYI - I name my variables so their types are evident: dVARIABLENAME for double, iVARIABLENAME for integer, sVARIABLENAME for string, etc.)

   iDfnRngBars = 5;

   dDgts    = (double)_Digits;
   dPipFct  = 1.0 * MathPow(10.0,-(dDgts-1));
//   
//--- find slope, diff between current MA value (dCurVlu) vs.  MA value at iDfnRngBars back  (dRngSttVlu)
//
// dPipFct = 0.0001, the factor to get results in pips from current data on AUDUSD with _Digits = 5.
      dCurSlp     =  dCurVlu - dRngSttVlu;
      dCurSlpPips =  dCurSlp / dPipFct;			
      
//--- Now the degrees of the range for line of dCurSlp
//
//--- Use ARCTAN2 to get radians and convert to degrees
//    Radians = ATAN2(x,y), iDfnRngBars is # of Bars included in slope calculation
      dCurRdn     =  MathArctan2((double)iDfnRngBars,dCurSlp);
      dCurRdnPips =  MathArctan2((double)iDfnRngBars,dCurSlpPips);

//--- Degrees = Radians * 180/PI()
      dCurDgr     = dCurRdn * (180/M_PI);    
      dCurDgrPips = dCurRdnPips * (180/M_PI);    

      


Here are the results: 



But everything seems to work fine when I do it in Excel:



($M$1 contains the same value as iDfnRngBars in the code: 5)

I'm very, very stuck here...

Thanks in advance for your help! 😁

 
Millard Melnyk:

Obviously, I'm doing something wrong, but I can't see it for the life of me. 

I'm testing against AUDUSD on a 5-minute chart.


(FYI - I name my variables so their types are evident: dVARIABLENAME for double, iVARIABLENAME for integer, sVARIABLENAME for string, etc.)


Here are the results: 



But everything seems to work fine when I do it in Excel:



($M$1 contains the same value as iDfnRngBars in the code: 5)

I'm very, very stuck here...

Thanks in advance for your help! 😁

X and Y are reverse in MQL.
 
Dominik Egert #:
X and Y are reverse in MQL.


Thank you.