"possible loss of data due to type conversion" despite correct explicit type casting.

 

Right, I have the following:

void CalculateRSquared(int Periods, int SMAMODE){

   if(Periods > 10){
   
      Periods = 10;
   
   }

   //---
   //// Declare dynamic arrays.
   double time[];
   double price[];
   double time_pow[];
   //---

   //---
   //// Resize arrays to the specified number of period.
   ArrayResize(time, Periods);
   ArrayResize(price, Periods);
   ArrayResize(time_pow, Periods);
   //---

   //---
   //Array to store values.
   for (int i = 0; i < Periods; i++) {
   
   time[i]     = (double)Time[i];
   price[i]    = Open[i];
   time_pow[i] = MathPow(time[i], 2);
   
   }
   //---

   //---
   //Calculate Sums & Averages
   double   SumOfPrices   = 0;
   double   SumOfPeriods  = 0;
   
   for (int i = 0; i < Periods; i++){
   
      SumOfPeriods   += time[i];
   
   }

   double SMA           = iMA(NULL, 0, Periods, 0, SMAMODE, PRICE_OPEN, 0);
   double AverageTime   = SumOfPeriods / Periods;
   //---

   double ExMinusAverage      = 0;
   double EyMinusAverage      = 0;
   double ExyAverage          = 0;
   double Ex2                 = 0;
   double Exy                 = 0;
   double EyMinusAveragePow2  = 0;

   for (int i = 0; i < Periods; i++) {
   
      ExMinusAverage     += (double)(time[i] - AverageTime);
      EyMinusAverage     += (price[i] - SMA);
      ExyAverage         += ((double)time[i] - AverageTime) * (price[i] - SMA);
      Ex2                += time_pow[i];
      Exy                += (double)time[i] * price[i];
      EyMinusAveragePow2 += MathPow(price[i] - SMA, 2);
   
   }

   double ExMinusAveragePow2 = 0;
   
   for (int i = 0; i <Periods; i++){
   
      ExMinusAveragePow2 += MathPow(time[i] - AverageTime,2);
   
   }

   double SRTExMinusAveragePow2    = sqrt(ExMinusAveragePow2 / (Periods - 1));
   double SRTEyMinusAveragePow2    = sqrt(EyMinusAveragePow2 / (Periods - 1));
   double CoVariance               = ExyAverage / (Periods - 1);
   double Variance                 = (SRTExMinusAveragePow2 * SRTEyMinusAveragePow2);
   double CorrelationCoefficient   = NormalizeDouble((CoVariance / Variance),2);
   double StandardDeviation        = NormalizeDouble(SRTEyMinusAveragePow2  / Point,2);
   double RSquared                 = NormalizeDouble(MathPow(CorrelationCoefficient,2)*100,2);
   
   PrintFormat("%0.0f",RSquared);
   PrintFormat("%0.0f",StandardDeviation); 
    
}

Why does MQL4 have a complete hissy fit about the following line:

ExMinusAverage     += (double)(time[i] - AverageTime);

When it is blatantly obvious that this s correctly typecast?

Is is so silly at times, its absolutely ridiculous. 

I am so tired of having my time wasted just because MQL4 decides it's going to be a complete spoilt little child. I am so tired of this software not doing what I tell it to bloody do! 

 
   ExMinusAveragePow2 = 0;

   for (int i = 0; i <Periods; i++)
   {
      ExMinusAveragePow2 += MathPow(time[i] - AverageTime,2);
   }
'ExMinusAveragePow2' - undeclared identifier
possible loss of data due to type conversion


The error is in other line (because that variable is not declared), and the warning also disappears if you declare the variable with "double" type

 
Manuel Alejandro Cercos Perez #:
'ExMinusAveragePow2' - undeclared identifier
possible loss of data due to type conversion


The error is in other line (because that variable is not declared), and the warning also disappears if you declare the variable with "double" type

'ExMinusAveragePow2 - has been declared as a double - still getting the same bloody error message. 

Why?

I am getting sick to the back teeth of screaming, I am getting so tired of ripping my hair out, I am sick and tired of a piece of software ignoring me. I have TOLD IT TO CONVERT TO THE CORRECT TYPE CAST. 

WHY IS IT NOT DOING AS IT'S TOLD!? 

I swear to God if I see what warning message one more time I am going to take and axe to this computer. 

ONE.MORE.TIME. OR THIS COMPUTER WILL GET SMASHED.

 
TheHonestPrussian #:

'ExMinusAveragePow2 - has been declared as a double - still getting the same bloody error message. 

Why?

I am getting sick to the back teeth of screaming, I am getting so tired of ripping my hair out, I am sick and tired of a piece of software ignoring me. I have TOLD IT TO CONVERT TO THE CORRECT TYPE CAST. 

WHY IS IT NOT DOING AS IT'S TOLD!? 

I swear to God if I see what warning message one more time I am going to take and axe to this computer. 

ONE.MORE.TIME. AND WILL SCREAM SO LOUD YOU WILL BE ABLE TO HEAR ME! 

time[i]     = double(ulong(Time[i]));
 
Sardion Maranatha #:
time[i]     = double(ulong(Time[i]));

Right, here is my revised code with your implementation:


void CalculateRSquared(int Periods, int SMAMODE){

   if(Periods > 10){
   
      Periods = 10;
   
   }

   //---
   //// Declare dynamic arrays.
   double time[];
   double price[];
   double time_pow[];
   //---

   //---
   //// Resize arrays to the specified number of period.
   ArrayResize(time, Periods);
   ArrayResize(price, Periods);
   ArrayResize(time_pow, Periods);
   //---

   //---
   //Array to store values.
   for (int i = 0; i < Periods; i++) {
   
   //time[i]      =  (double)Time[i];
   time[i]        = double(ulong(Time[i]));
   price[i]       =  Open[i];
   time_pow[i]    =  MathPow(time[i], 2);
   
   }
   //---

   //---
   //Calculate Sums & Averages
   double   SumOfPeriods  = 0;
   
   for (int i = 0; i < Periods; i++){
   
      SumOfPeriods   += time[i];
   
   }

   double SMA           = iMA(NULL, 0, Periods, 0, SMAMODE, PRICE_OPEN, 0);
   double AverageTime   = SumOfPeriods / Periods;
   //---

   ExMinusAverage      = 0;
   EyMinusAverage      = 0;
   ExyAverage          = 0;
   Ex2                 = 0;
   Exy                 = 0;
   EyMinusAveragePow2  = 0;

   for (int i = 0; i < Periods; i++) {
      
      ExMinusAverage     += (time[i] - AverageTime);
      EyMinusAverage     += (price[i] - SMA);
      ExyAverage         += (time[i] - AverageTime) * (price[i] - SMA);
      Ex2                += time_pow[i];
      Exy                += time[i] * price[i];
      EyMinusAveragePow2 += MathPow(price[i] - SMA, 2);
   
   }

   ExMinusAveragePow2 = 0;
   
   for (int i = 0; i < Periods; i++){
   
      ExMinusAveragePow2 += MathPow(time[i] - AverageTime,2);
   
   }

   double SRTExMinusAveragePow2    = sqrt(ExMinusAveragePow2 / (Periods - 1));
   double SRTEyMinusAveragePow2    = sqrt(EyMinusAveragePow2 / (Periods - 1));
   double CoVariance               = ExyAverage / (Periods - 1);
   double Variance                 = (SRTExMinusAveragePow2 * SRTEyMinusAveragePow2);
   double CorrelationCoefficient   = NormalizeDouble((CoVariance / Variance),2);
   double StandardDeviation        = NormalizeDouble(SRTEyMinusAveragePow2  / Point,2);
   double RSquared                 = NormalizeDouble(MathPow(CorrelationCoefficient,2)*100,2);
   
   return;
    
}

...so why am I STILL getting the same warning message...?

 
Why are you assigning times to a double variable? 

Anyway, I suggest to use 

double(formula) 

instead of 

(double)value

So the entire formula will be converted.