New MetaTrader 4 Build 970: Simplified demo account opening and expanded MQL4 features

Back to topics list  | 1 2 3 4 5 6 7 8 9 10 To post a new topic, please log in or register
avatar
8
minimax2000 2016.06.24 04:19 #
 

Please fix iMAOnArray's bug on next update. It returns wrong value for array passed as function argument. 

The code below shows that iMAOnArray returns diffrent result for argument array and local array though they are equal. 

loop0:  array_ma=1.000000  /  a_ma=1.000000
loop1:  array_ma=1.000000  /  a_ma=2.000000
loop2:  array_ma=1.000000  /  a_ma=3.000000

int OnCalculate(...)
{
        double array[10];
        ArraySetAsSeries(array, true);
        ArrayInitialize(array, 0);
        
        for (int i = 0; i < 3; i++)
        {
                array[0] = i+1;
                PrintArrayMA(i, array);         // buggy when passed as function's argument
        }
        
        return(rates_total);
}
//+------------------------------------------------------------------+

void PrintArrayMA(int i, const double &array[])
{       
        double a[];
        ArraySetAsSeries(a, true);
        ArrayCopy(a, array);
        
        double array_ma = iMAOnArray(array, 0, 1, 0, MODE_SMA, 0);
        double a_ma     = iMAOnArray(a,     0, 1, 0, MODE_SMA, 0);
        
        if (ArrayCompare(array, a) == 0)
                PrintFormat("loop%d:  array_ma=%lf  /  a_ma=%lf", i, array_ma, a_ma);   // array_ma and a_ma should be the same
}

 


Attached files:
  imaonarraybug.mq4  (1.33 KB)
avatar
1197
FMIC 2016.06.24 05:00 #
 
minimax2000:

Please fix iMAOnArray's bug on next update. It returns wrong value for array passed as function argument. 

The code below shows that iMAOnArray returns diffrent result for argument array and local array though they are equal. 

loop0:  array_ma=1.000000  /  a_ma=1.000000
loop1:  array_ma=1.000000  /  a_ma=2.000000
loop2:  array_ma=1.000000  /  a_ma=3.000000

That is because you are using the function incorrectly. Read the documentation. The use of "ixxOnArray" functions should only be used on arrays that are NOT set as "Series". The indicator is calculated from left to right.

ArraySetAsSeries( abc, false ); // Must set to false and indexing must be adjusted as necessary
avatar
1109
Ovo 2016.06.24 05:21 #
 
jamescater:

You can also pass it around as a parameter to another function.

I was just showing you how you translate the "c" like function pointer call into a virtual function call

 Well, yes you can, but in OOP it does not have much use when you can pass complete objects as arguments. On the other hand the winapi offers a few asynchronous function calls with a callback function in argument. It would be helpful to have a chance to use them. So I was wondering if someone already knows if the MQL function pointers were compatible with such a call.

 

avatar
1197
FMIC 2016.06.24 05:31 #
 
Ovo:

 Well, yes you can, but in OOP it does not have much use when you can pass complete objects as arguments. On the other hand the winapi offers a few asynchronous function calls with a callback function in argument. It would be helpful to have a chance to use them. So I was wondering if someone already knows if the MQL function pointers are compatible with such a call.

I don't know the answer, but maybe you can try coding a small test to see if you can call back into MetaTrader from a DLL. However, I suspect that passing parameters will be tricky as I don't think it will be compatible, but maybe just a normal "void" function call with no parameters might work.
avatar
8
minimax2000 2016.06.24 15:50 #
 
FMIC:

That is because you are using the function incorrectly. Read the documentation. The use of "ixxOnArray" functions should only be used on arrays that are NOT set as "Series". The indicator is calculated from left to right.

Thank you, FMIC.

I modified the code so that iMAOnArray is used on non-series arrays. But iMAOnArray still returns diffrent result for argument array and local array though they are equal.

loop0:  array_ma=1.000000  /  a_ma=1.000000
loop1:  array_ma=1.000000  /  a_ma=2.000000

loop2:  array_ma=1.000000  /  a_ma=3.000000

int OnCalculate(...)
{
        double array[10];
        ArrayInitialize(array, 0);
        
        for (int i = 0; i < 3; i++)
        {
                array[9] = i+1;
                PrintArrayMA(i, array);         // buggy when passed as function's argument
        }
        
        return(rates_total);
}

void PrintArrayMA(int i, const double &array[])
{       
        double a[];
        ArrayCopy(a, array);
        
        double array_ma = iMAOnArray(array, 0, 1, 0, MODE_SMA, 0);
        double a_ma     = iMAOnArray(a,     0, 1, 0, MODE_SMA, 0);
        
        if (ArrayCompare(array, a) == 0)
                PrintFormat("loop%d:  array_ma=%lf  /  a_ma=%lf", i, array_ma, a_ma);   // array_ma and a_ma should be the same
}

 

Attached files:
  imaonarraybug_1.mq4  (1.27 KB)
avatar
1197
FMIC 2016.06.24 17:00 #
 
minimax2000:

Thank you, FMIC.

I modified the code so that iMAOnArray is used on non-series arrays. But iMAOnArray still returns diffrent result for argument array and local array though they are equal.

loop0:  array_ma=1.000000  /  a_ma=1.000000
loop1:  array_ma=1.000000  /  a_ma=2.000000

loop2:  array_ma=1.000000  /  a_ma=3.000000

The issue seems to be related to the total number of items and using 0 to mean the whole array. There seems to be a issue when using dynamic arrays (or maybe arrays passed by reference), causing the "total" to be off. So either use an explicit "total" or use "ArraySize()" as in the following examples:

t        = 10;
array_ma = iMAOnArray(array, t, 1, 0, MODE_SMA, 0);
a_ma     = iMAOnArray(a,     t, 1, 0, MODE_SMA, 0);
array_ma = iMAOnArray(array, ArraySize(array), 1, 0, MODE_SMA, 0);
a_ma     = iMAOnArray(a,     ArraySize(a),     1, 0, MODE_SMA, 0);

However, since this is not related to build 970/971, as the same issue also occurs on 910. I suggest starting a separate thread if needed, but you should instead just report it directly via the service desk and link these few posts in your report.

avatar
8
minimax2000 2016.06.25 00:41 #
 
FMIC:

The issue seems to be related to the total number of items and using 0 to mean the whole array. There seems to be a issue when using dynamic arrays (or maybe arrays passed by reference), causing the "total" to be off. So either use an explicit "total" or use "ArraySize()" as in the following examples:

However, since this is not related to build 970/971, as the same issue also occurs on 910. I suggest starting a separate thread if needed, but you should instead just report it directly via the service desk and link these few posts in your report.

The result doesn't change  on 950 and 971 though I explicitly set the total. I will report this problem to service desk.

Thank you very much for your advises, FMIC. 

avatar
1197
FMIC 2016.06.25 00:52 #
 
minimax2000:

The result doesn't change  on 950 and 971 though I explicitly set the total. I will report this problem to service desk.

When you explicitly set the "total", it does correct the issue. It did so in the tests I carried out on 971 and 910.
Back to topics list   | 1 2 3 4 5 6 7 8 9 10  

To add comments, please log in or register