EA will not compile

 

Hi,

edit... I have Metatrader 5. Version 5.00 build 4232 11 March 2024

I just made a very small change to my EA code and now it wont compile. I get the following error which I wasn't getting before. I haven't changed this bit of code at all.



Code:



int Lin_Reg_Slope(int diagFileHandle, double &tDataSec[], double &balance[], double &dCustomPerformanceMetric)
  {

//SIZE OF BALANCE CURVE
   int nBalanceCurve = ArraySize(balance);

//DEFINE MATRIX OBJECT
   CMatrixDouble xy(nBalanceCurve,2); //--- CMatrixDouble object
   for(int i=1; i<=nBalanceCurve; i++)
     {
      xy[i-1].Set(0,tDataSec[i-1]);
      xy[i-1].Set(1,balance[i-1]);
      //Print(balance[i]); // for debug
     }

//LINEAR REGRESSION ANALYSIS
   CLinReg        linear_regression;
   CLinearModel   linear_model;
   CLRReport      linear_report;
   int retcode;
   linear_regression.LRBuild(xy,nBalanceCurve,1,retcode,linear_model,linear_report);
   if(retcode!=1)
     {
      Print("Linear regression failed, error code=",retcode);
      return(0.0);
     }

//GET THE REGRESSION LINE COEFFICIENTS
   int nvars;
   double coefficients[];
   linear_regression.LRUnpack(linear_model,coefficients,nvars);
   double coeff_a=coefficients[0];
   double coeff_b=coefficients[1];
   PrintFormat("y = %.1f x + %.1f",coeff_a,coeff_b);

// ASSIGN VALUE TO CUSTOM METRIC VARIABLE
   dCustomPerformanceMetric = coeff_a;

//WRITE OUT DIAGNOSTIC DATA
   if(diagnosticLoggingLevel >= 1)
     {
      FileWrite(diagFileHandle, "\nLinear Regression (y=ax + b) Slope a:", coeff_a);
      FileWrite(diagFileHandle, "\nLinear Regression (y=ax + b) intercept b:", coeff_b);
     }



   return (nBalanceCurve);
  }

Any ideas what the problem is? I think I recall an update being installed at some point.


E

 
EdFuk:
      xy[i-1].Set(0,tDataSec[i-1]);       xy[i-1].Set(1,balance[i-1]);

Seems like your problem is in this line:


      xy[i-1].Set(0,tDataSec[i-1]);
      xy[i-1].Set(1,balance[i-1]);


xy.operator[] will return a double. You cannot do

double.Set()

as this is not implemented. - At least thats how I read this from the little information you gave.

 
Dominik Egert #:

Seems like your problem is in this line:



xy.operator[] will return a double. You cannot do

as this is not implemented. - At least thats how I read this from the little information you gave.

Hmm, well I haven’t touched this code for years. Maybe some updated error checking came in with the new build?

I will have a double check at previous versions I have but seems strange. 
 
EdFuk #:
Hmm, well I haven’t touched this code for years. Maybe some updated error checking came in with the new build?

I will have a double check at previous versions I have but seems strange. 
What if you revert the changes you did??

Hope you have git or SVN in use. If not, I suggest you get GitAhead or TortoiseGit or TortoisesSVN.


 

I think that the problem is you declare a matrix:

CMatrixDouble xy(nBalanceCurve,2); //--- CMatrixDouble object

but your .set(idx,val) function with only two values (index and value) is in this way only valid vor vectors.

Maybe that the compiler could handle this previously ...

 
Dominik Egert #:
What if you revert the changes you did??

Hope you have git or SVN in use. If not, I suggest you get GitAhead or TortoiseGit or TortoisesSVN.


Yes, I use git. Reverted back to the last known version to run and it doesn’t compile, with the same error. There must have been a change to the CMatrixDouble class just needed to find what. 

 
Carl Schreiber #:

I think that the problem is you declare a matrix:

but your .set(idx,val) function with only two values (index and value) is in this way only valid vor vectors.

Maybe that the compiler could handle this previously ...

Yes, I will have to look and see what’s changed in the class. 

 
EdFuk #:

Yes, I use git. Reverted back to the last known version to run and it doesn’t compile, with the same error. There must have been a change to the CMatrixDouble class just needed to find what. 

ALGLib was overhauled in one of the recent updates. There were significant changes.

My guess is, that you got hit by these changes.
 

How do I find out what version of Alglib I have?

Is there an update log for MT5/MQL5 and libraries etc?


I changed the code to include row number as follows but now it complains that there are too many parameters (see below). It looks like the CMatrixDouble Set method isn't being accessed but a builtin bool Vector Set method is. Any ideas?


int Lin_Reg_Slope(int diagFileHandle, double &tDataSec[], double &balance[], double &dCustomPerformanceMetric)
  {

//SIZE OF BALANCE CURVE
   int nBalanceCurve = ArraySize(balance);

//DEFINE MATRIX OBJECT
   CMatrixDouble xy(nBalanceCurve,2); //--- CMatrixDouble object
   for(int i=1; i<=nBalanceCurve; i++)
     {
      xy[i-1].Set(i-1, 0,tDataSec[i-1]);
      xy[i-1].Set(i-1, 1,balance[i-1]);
      //Print(balance[i]); // for debug
     }

//LINEAR REGRESSION ANALYSIS
   CLinReg        linear_regression;
   CLinearModel   linear_model;
   CLRReport      linear_report;
   int retcode;
   linear_regression.LRBuild(xy,nBalanceCurve,1,retcode,linear_model,linear_report);
   if(retcode!=1)
     {
      Print("Linear regression failed, error code=",retcode);
      return(0.0);
     }

//GET THE REGRESSION LINE COEFFICIENTS
   int nvars;
   double coefficients[];
   linear_regression.LRUnpack(linear_model,coefficients,nvars);
   double coeff_a=coefficients[0];
   double coeff_b=coefficients[1];
   PrintFormat("y = %.1f x + %.1f",coeff_a,coeff_b);

// ASSIGN VALUE TO CUSTOM METRIC VARIABLE
   dCustomPerformanceMetric = coeff_a;

//WRITE OUT DIAGNOSTIC DATA
   if(diagnosticLoggingLevel >= 1)
     {
      FileWrite(diagFileHandle, "\nLinear Regression (y=ax + b) Slope a:", coeff_a);
      FileWrite(diagFileHandle, "\nLinear Regression (y=ax + b) intercept b:", coeff_b);
     }



   return (nBalanceCurve);
  }


Many thanks,


Ed

 
Carl Schreiber #:

I think that the problem is you declare a matrix:

but your .set(idx,val) function with only two values (index and value) is in this way only valid vor vectors.

Maybe that the compiler could handle this previously ...

Yes I agree,

But when I change the parameters to (row, col, val) I get an error as follows. It seems to be trying to access the Set method from a built in vector class even though I have declared xy as a CMatrixDouble. Any ideas?

 
EdFuk #:

Yes I agree,

But when I change the parameters to (row, col, val) I get an error as follows. It seems to be trying to access the Set method from a built in vector class even though I have declared xy as a CMatrixDouble. Any ideas?

All sorted. There must have been a change to indexing which I didn’t spot. 
Reason: