Download MetaTrader 5
To add comments, please log in or register
You sell neither signals nor apps? No problem, everyone can make profit!
Vlaser91
53
Vlaser91 2015.12.06 19:33 

Hi Guys,

I am parsing a series of rates and then copying the .Open part into a new array, this is done via:

   MqlRates rates[];
   double copyrates[100];
   ArraySetAsSeries(rates,true);
   int copied=CopyRates(Symbol(),0,0,100,rates);
   
   for (int i=0;i<=(copied-1);i++)  //0 to Copied-1 means that you have 100 elements. 0 to Copied means 101 and hence its an error of bounds.
      {
         copyrates[i]=rates[i].open;
      }

The idea now is to pass the entire copyrates array into a C++ program complied as a .dll. The C++ routine is simple and is just generating the sum of the components of the array. This is how I have implement it:

double std_est(double p[])
{
        int z = sizeof(p);
        int sum = 0;
        for (int i=0; i<=z; ++i)
        {
                sum = sum + p[i];
        }
        return(sum);

}

I then declare the function at the Import section of the MQL code via:

double std_est(double & p[]);

and then try to call it (and there is the problem) via:

Alert("The sum is: ",std_est(copyrates));

The result I am getting is:

The sum is: 5.0

Anyone has any idea what is going on here?

Many thanks for the interest Guys!

whroeder1
13641
whroeder1 2015.12.06 21:05  
  1. Instead of CopyRates and then copying the open you could just use CopyOpen - MQL4 Documentation
  2. int z = sizeof(p);
    for (int i=0; i<=z; ++i)
    This means you access one past the end.
  3. for (int i=0;i<=(copied-1);i++)
    for (int i=0;i<  copied   ;i++) // Use the C style [0 .. N)

  4. How can sizeof(p) possibly work? It's a compile time statement; pass the length.



Vlaser91
53
Vlaser91 2015.12.06 22:58  
WHRoeder:
  1. Instead of CopyRates and then copying the open you could just use CopyOpen - MQL4 Documentation
  2. This means you access one past the end.

  3. How can sizeof(p) possibly work? It's a compile time statement; pass the length.



Thanks for the above WHRoeder. I have made the relevant adjustment however, even by explicitly setting the length in the C function, this doesn't work. It appears that this is looping through a count to 100 (array size) and the output is coming out 100. I am sure that Copyrates holds values cause I run stop checks with Mqlrates Open.
/
To add comments, please log in or register