A function can't return an array to mq4 (int, double, string, datetime is all there is)
Pass the array by reference to the function.
K. Thanks. I shall try it and let you know.
A function can't return an array to mq4 (int, double, string, datetime is all there is)
Pass the array by reference to the function.
declare it by reference in mql4 and on the c++ side you will receive a pointer to the array (to the first element of the array). You can read and write to this array from C++ and by doing so you will be directly accessing the mql4 array. After the function has returned your mql4 will find the modified values in this array.
You can also directly write into indicator buffers from within the DLL. There is a Pascal example for such an indicator in the FPC/Lazarus tutorial on forexfactory.com. The Pascal example and everything else written there can be directly translated to C++, Pascal is an excellent and clean language to teach and explain such concepts, data structures and algorithms (and also for implementing them for production) without the C++ typical confusion, its hilarious pointer syntax and all its other bizarre anomalies.
Be careful to not read or write beyond the size of the array or you will provoke a crash. Always pass the array size as a separate parameter and make the C++ function so that it will respect this number under all circumstances.
Hi Roeder,
Can you please explain with an example?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This is the code that I am using in creating dll with VC++ . My function DataCollection1(). shall return 2 variables stored in a array DataCollection1Return[2].
MT4_EXPFUNC double __stdcall DataCollection1(int Var1, double Var2, double Var3){
myVariable2 = Var2; // Tracking New High}
This is the code in mql4 to get the variable stored in the array
for(i=0;i<=2;i++)
{
DataCollection1Return[i]= DataCollection1(int Var1, double Var2, double Var3);
Var2=DataCollection1Return[1];
Var3=DataCollection1Return[2];
i++;
}
Is my code correct, or kindly correct it to get the elements in the array