Error Message: "parameter conversion not allowed" passing values to a function in an external *.mqh file

 

Good Day Everyone!


I am a freetime and hobby programer with not so much experience in MQL5 but I do my best and only ask for help as a last option. Since many days I am trying to solve a problem until I finally have decided to post it in the forum. I will appreciate strongly if you can hep me with it :).

In a Main File I have created an Array of Struct that I am trying to pass to a function in an external *.mqh file. I have checked many articles in the forum but I am not able to find what is wrong. Here is the code:

Main File (OnInit and other less important parts were obviated):

#include "LinearRegression.mqh"

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   struct MainArrayBasis
     {
      datetime          time;          // Last price update time
      double            Close;     // Close price
     };
   MainArrayBasis MainArray[], TempMainArray[];
   int bars=Bars(_Symbol,(ENUM_TIMEFRAMES)inp_timeframe);
   ArrayResize(MainArray, bars);
   for(int i=0; i<bars; i++)
     {
      MainArray[i].time= iTime(_Symbol,(ENUM_TIMEFRAMES)inp_timeframe,i);
      MainArray[i].Close=(iClose(_Symbol, (ENUM_TIMEFRAMES) inp_timeframe, i));
     }
     double gradient=0.0;
     double c_point=0.0;
     double StdDev=0.0;

   MqlDateTime today, comp_day; //Add structure to today and comp_day
   TimeToStruct(MainArray[0].time,today); //Assignation of MainArray to today
   int TempMainArrayCounter=0;
   for(int i=0; i<bars; i++)
     {
      TimeToStruct(MainArray[i].time,comp_day);
      if(comp_day.day==today.day)
        {
         TempMainArrayCounter=TempMainArrayCounter+1;
        }
      else
        {
         i=bars;
        }
     }
   ArrayResize(TempMainArray, TempMainArrayCounter);
   for(int i=0; i<bars; i++)
     {
      TimeToStruct(MainArray[i].time,comp_day);
      if(comp_day.day==today.day)
        {
         TempMainArray[i].time=MainArray[i].time;
         TempMainArray[i].Close=MainArray[i].Close;
        }
      else
        {
         i=bars;
        }
     }
LinearRegression(TempMainArray, TempMainArrayCounter, gradient, c_point);                       // <---- HERE I HAVE THE PROBLEM

  }


External *.mqh file

struct MainArrayBasisLR
  {
   datetime          timeLR;          // Last price update time
   double            CloseLR;     // Close price
  };

void LinearRegression(MainArrayBasisLR &TempMainArrayLR[], int TempMainArrayCounterLR, double &gradientLR, double &c_pointLR)
  {
   double  d_gradientLR=0, d_c_pointLR=0, learning_rateLR=0.01;
   int iterationLR=1000;
   for(int i=0; i<iterationLR; ++i)
     {
      d_gradientLR=0;
      d_c_pointLR=0;
      for(int j=0; j<TempMainArrayCounterLR; ++j)
        {
         d_gradientLR=d_gradientLR-(2/TempMainArrayCounterLR)*TempMainArrayLR[j].CloseLR*(j-((gradientLR*TempMainArrayLR[j].CloseLR+c_pointLR)));
         d_c_pointLR=d_c_pointLR-(2/TempMainArrayCounterLR)*(j-((gradientLR*TempMainArrayLR[j].CloseLR+c_pointLR)));
        }
      gradientLR=gradientLR-(learning_rateLR*d_gradientLR);
      c_pointLR=c_pointLR-(learning_rateLR*d_c_pointLR);
     }
  }

The error message is this:


I will appreciate your help with this topic


Thanks

Files:
 
There is no error message in your post, seems something went wrong.
 
Tobias Johannes Zimmer #:
There is no error message in your post, seems something went wrong.

I have added it as a file


Thanks

 
You are passing an array of MainArrayBasis.
   MainArrayBasis MainArray[], TempMainArray[];
   ⋮
   LinearRegression(TempMainArray, …
The function requires an array of MainArrayBasesLR
void LinearRegression(MainArrayBasisLR &TempMainArrayLR[], …
Pass the correct type.
 

@William Roeder: Thanks for the answer. After many iterations I am still at the beginning having the same Error Message. Some of the iterations were:


1. Innitially I assumed that the struct array on both is the same, and therefore it should be the same type (the innitial state). I have received the already known Error Message.

struct MainArrayBasis
  {
   datetime          time;          // Last price update time
   double            Close;     // Close price
  };

vs

struct MainArrayBasisLR
  {
   datetime          timeLR;          // Last price update time
   double            CloseLR;     // Close price
  };


2. Later on I have modified the LinearRegression.mqh in the struct to look similar to the Main file.  I have received the same Error Message.

struct MainArrayBasis
  {
   datetime          time;          // Last price update time
   double            Close;     // Close price
  };

vs

struct MainArrayBasis
  {
   datetime          timeLR;          // Last price update time
   double            CloseLR;     // Close price
  };


3. Trying to use the struct array from the Main file as a global parameter, I have disabled the struct array in the file:

//struct MainArrayBasis
//  {
//   datetime          timeLR;          // Last price update time
//   double            CloseLR;     // Close price
//  };

AND

void LinearRegression(MainArrayBasis &TempMainArrayLR[], int TempMainArrayCounterLR, double &gradientLR, double &c_pointLR)

But after all I am geting even more error Messages of different types.


So maybe I haven't understand you clearly what you have written on the table. Could you tell me if there is some wrong assumption? as well as any more detailed suggestion?

 As one of the articles in the forum as a guide I have used:

https://www.mql5.com/en/forum/358732

Thanks

Tell me why the error occurs: "'buffer' - parameter conversion not allowed"
Tell me why the error occurs: "'buffer' - parameter conversion not allowed"
  • 2020.12.24
  • www.mql5.com
For some reason, it swears at the line with the error buffer - parameter conversion not allowed when I try to pass an array of structures by refere...
 
  1. The include file defines the struct. Drop with the other one.

  2. Grzegorz Galazka #: 1. Innitially I assumed that the struct array on both is the same,

    MainArrayBasis and MainArrayBasisLR are two completely different struct. Only you think thay are the same.

  3. Grzegorz Galazka #: 2. Later on I have modified the LinearRegression.mqh in the struct to look similar to the Main file. 

    You define the same struct twice, in the main and in the included. Can't do that. Drop the other one.

 

@William Roeder: thanks for the prompt answer. I got your point and is completely logic. It is necessary to use the same struct on the Main file as well as in the included function. 

I have tried to use a similar syntax as in the article https://www.mql5.com/en/forum/358732 where the struct is declared as a Global Variable (outside all functions in the Main file). But in my case I have to feed the MainArrayTemp constantly inside the OnCalculate() function in the Main file. Than I again tried to pass the struct arrays to the function and is not working.

So I had to reformulated my question: Which command or syntax should I use to pass a local struct array into an external function in an *.mqh file?

Thanks for your help!

Tell me why the error occurs: "'buffer' - parameter conversion not allowed"
Tell me why the error occurs: "'buffer' - parameter conversion not allowed"
  • 2020.12.24
  • www.mql5.com
For some reason, it swears at the line with the error buffer - parameter conversion not allowed when I try to pass an array of structures by refere...
 
Grzegorz Galazka #: Which command or syntax should I use to pass a local struct array into an external function 
void LinearRegression(MainArrayBasis &TempMainArrayLR[], int TempMainArrayCounterLR, double &gradientLR, double &c_pointLR)
Just call the function.
   MainArrayBasis locArr[]; …
   LinearRegression(locArr, …);
 

@William Roeder: Thanks again! 


After applying your recommendations and setting the struct array declaration in the global scope I got no Error Message on the Main file but in the *.mqh file. So after checking many articles I have found this one where you helped another guy with a similar situation few years ago:


https://www.mql5.com/en/forum/203579


Forum on trading, automated trading systems and testing trading strategies

#include and declaring global variables

William Roeder, 2017.06.06 16:49

mqh files do not get errors. You do not compile them. You include them in the main program and compile that.


So considering that I received no Error Message after compiling the Main file, everything should be ok? What do you mean with "including them in the main program and compile that"?

The Error Message that I receive from the *.mqh is attached to the comment. There you can see that the Struct Array data type on the Main files global scope apparently had no efect (MainArrayBasis - declaration without type) and therefore the declared structure (TempMainArrayLR) is "undeclared". Is this normal in functions in separated *.mqh files? Can I consider that the problem is solved?

Thanks for the help :)

#include and declaring global variables
#include and declaring global variables
  • 2017.06.06
  • www.mql5.com
Hi friends, I'm working on an EA and I'm going to lighten my EA code lines, so I decided to use the #include preprocessor and put some of my functi...
Files:
Reason: