Empty4 v600 for Coders

User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Empty4 v600 for Coders

Post by snailbeard »

ArraySize() of two-dimensional array passed by reference always returns zero.

The new compiler is a big improvement on the old compiler and it has exposed at lot of issues with types and returned values, array underflow and array overflow.

For a couple of days I have been trying to understand what I had to change to solve this last issue. Initially, I thought it must be a misunderstanding on my part. This belief was reinforced when I searched and could not find anyone else reporting an issue with ArraySize of a multidimensional array passed by reference.

However, after writing a very simple test, I still can't see anything wrong with the code and I am starting to think it is a problem in Empty4, but it doesn't make sense that it has not been reported by others.

Anyway, here is my test code and results. Also I found that ArrayRange() seems to be OK so I'm working on a substitute ArraySizeMT4B600() for the time being.

Code: Select all

//+------------------------------------------------------------------+
//|                                            Testb625ArraySize.mq4 |
//|                                                       Snailbeard |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Snailbeard"
#property link      ""
#property version   "1.00"
#property strict

#define IntToStr IntegerToString

int glbArr1[5][2];

int glbTestDataIn[5][2]=
  {
   11,12,
   21,13,
   31,14,
   41,15,
   51,16
  };

int glbTestDataOut[5][2]=
  {
   0,0,
   11,12,
   21,13,
   31,14,
   41,15
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void forceAppExit()
  {
/*
   int a = 1;
   int b = 0;
   int c = a/b; // force divide by zero
   */
   ExpertRemove();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void tryPassByRef(int &x,double &y,double  &z[])
  {
   double offset=0.1;
   int count=0;

   int iSizeOfZ=0;

   iSizeOfZ=ArraySize(z);
   if(iSizeOfZ<1)
     {
      Print("testPassByRef(): iSizeOfZ < 1: ");
      Print("ERROR z[] Array size is wrong!");
      forceAppExit();
      return;
     }

   for(count=0; count<10; count++)
     {
      if(count>=ArraySize(z))
         break;

      z[count]=count;
     }
   x  = count;
   y  = offset + count;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void testTryPassByRef()
  {
   int ix=0;
   double dy=0.0;
   double az[5];

   tryPassByRef(ix,dy,az);
   Print("testTryPassByRef() results: ");
   Print("ix: ",ix,", dy: ",dy,", az[ix-1]: ",(az[(ix-1)]));
   Print("---");

  }
//+------------------------------------------------------------------+
//| bwaShift2DimArrayOfInt()                                                       |
//+------------------------------------------------------------------+
bool bwaShift2DimArrayOfInt(int &arrData[][],int dim1,int dim2)
  {
  
  
   Print("Two dimensions: ");
   int dim0=ArrayRange(arrData,0);
   int dim1=ArrayRange(arrData,1);
   
   PrintFormat("ArrayRange: dim1 = %d, dim2 = %d \n", dim0, dim1);
     
   int maxsize=ArraySize(arrData);
   if( maxsize == 0 )
   {
      Print("bwaShift2DimArrayOfInt(): maxsize == 0 ");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      Print("ERROR ArraySize returned Zero!");
      forceAppExit();
      return(false);
   
   }
   else if((dim1*dim2)>maxsize)
     {
      Print("bwaShift2DimArrayOfInt(): (dim1 * dim2) > maxsize: ");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      Print("ERROR Array size is wrong!");
      forceAppExit();
      return(false);
     } 
   else {
      Print("bwaShift2DimArrayOfInt(): ");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      Print("SUCCESS ArraySize() returned POSITIVE INT!");
     }

   for(int i1=0; i1<dim1; i1++)
     {
      int rIdxLast = dim1  - 1 -  i1;
      int rIdxPrev = rIdxLast - 1;
      if(rIdxPrev<0)
         break;

      for(int i2=0; i2<dim2; i2++)
        {
         arrData[rIdxLast][i2]=arrData[rIdxPrev][i2];
         if(rIdxPrev==0) arrData[0][i2]=0;
        }
     }
   return(true);
  }
//+------------------------------------------------------------------+
//| bwaCompare2DimArrayOfInt()                                                       |
//+------------------------------------------------------------------+
bool bwaCompare2DimArrayOfInt(int &arrData[][],int &arrData2[][],int dim1,int dim2)
  {
   bool bSuccess= true;
   bool bReport = false;

   int maxsize=ArraySize(arrData);
   if( maxsize == 0 )
   {
      Print("bwaShift2DimArrayOfInt(): maxsize == 0 ");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      Print("ERROR ArraySize returned Zero!");
      forceAppExit();
      return(false);
   }
   else if((dim1*dim2)>maxsize)
     {
      Print("bwaCompare2DimArrayOfInt() : Array arrData[][] dimension error!");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      return(false);
     }
   int size2=ArraySize(arrData2);
   if((dim1*dim2)>size2)
     {
      Print("bwaCompare2DimArrayOfInt() : Array arrData2[][] dimension error!");
      Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
      return(false);
     }
   int i1 = 0;
   int i2 = 0;
   for(i1 = 0; i1 < dim1; i1++ )
     {
      int rIdxLast=dim1-1-i1;

      for(i2=0; i2<dim2; i2++)
        {
         if(arrData[rIdxLast][i2]!=arrData2[rIdxLast][i2])
           {
            bSuccess=false;
            if(bReport)
              {
               Print("bwaCompare2DimArrayOfInt() : Arrays are different!!!");
               Print("index: "
                     +IntToStr(rIdxLast)+", "
                     +IntToStr(i2)+" : arrData: "
                     +IntToStr(arrData[rIdxLast][i2])+", "+", arrData2 : "
                     +IntToStr(arrData2[rIdxLast][i2]));
              }
           }
        }
     }
   Print("bwaCompare2DimArrayOfInt(): No. of Ints compared: ["
         +IntToStr(i1)+"], ["
         +IntToStr(i2)+"]");
   if((bSuccess==false) && (bReport==true))
      for(i1=0; i1<dim1; i1++)
         for(i2=0; i2<dim2; i2++)
            Print("index: "
                  +IntToStr(i1)+", "
                  +IntToStr(i2)+" : arrData: "
                  +IntToStr(arrData[i1][i2])+", "+", arrData2 : "
                  +IntToStr(arrData2[i1][i2]));

   return(bSuccess);
  }
//+------------------------------------------------------------------+
//| testbwaShift2DimArrayOfDoubles()                                                       |
//+------------------------------------------------------------------+
void test_glbShift2DimArrayOfInt()
  {
   Print("\n\nTest using GLOBAL array:");

//-----------------------------------------------------------
   int localDynArr1[5][2];
   Print("\n\nUsing Dynamic array: test_glbShift2DimArrayOfInt():");
   Print("ArraySize(localDynArr1) : ",(ArraySize(localDynArr1)));
   Print("ArraySize(glbTestDataIn) : ",(ArraySize(glbTestDataIn)));
   ArrayCopy(localDynArr1,glbTestDataIn,0,0,WHOLE_ARRAY);

   bool bSuccess=bwaShift2DimArrayOfInt(localDynArr1,5,2);
   if(bSuccess==false) Print("Test Failed: [glb] testbwaShift2DimArrayOfInt()");
   else
     {
      bSuccess=bwaCompare2DimArrayOfInt(localDynArr1,glbTestDataOut,5,2);
      if(bSuccess==false) Print("Test Failed: [glb] bwaCompare2DimArrayOfInt()");
      else Print("Test Passed: [glb] bwaCompare2DimArrayOfInt()");
     }
  }
//+------------------------------------------------------------------+
//| testbwaShift2DimArrayOfDoubles()                                                       |
//+------------------------------------------------------------------+
void test_bwaShift2DimArrayOfInt()
  {
   static int testDataIn[5][2]=
     {
      11,12,
      21,13,
      31,14,
      41,15,
      51,16
     };

   static int testDataOut[5][2]=
     {
      0,0,
      11,12,
      21,13,
      31,14,
      41,15
     };

//-----------------------------------------------------------
   int localDynArr1[5][2];
   Print("\n\nUsing Dynamic array: test_bwaShift2DimArrayOfInt():");
   Print("ArraySize(localDynArr1) : ",(ArraySize(localDynArr1)));
   Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
   ArrayCopy(localDynArr1,testDataIn,0,0,WHOLE_ARRAY);

   bool bSuccess=bwaShift2DimArrayOfInt(localDynArr1,5,2);
   if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
   else
     {
      bSuccess=bwaCompare2DimArrayOfInt(localDynArr1,testDataOut,5,2);
      if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
      else Print("Test Passed: bwaCompare2DimArrayOfInt()");
     }

//-----------------------------------------------------------
/// Test again with static array
   static int localStaticArr1[5][2];
   Print("\n\nUsing Local Static array: test_bwaShift2DimArrayOfInt():");
   Print("ArraySize(localStaticArr1) : ",(ArraySize(localStaticArr1)));
   Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
   ArrayCopy(localStaticArr1,testDataIn,0,0,WHOLE_ARRAY);

   bSuccess=bwaShift2DimArrayOfInt(localStaticArr1,5,2);
   if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
   else
     {
      bSuccess=bwaCompare2DimArrayOfInt(localStaticArr1,testDataOut,5,2);
      if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
      else Print("Test Passed: bwaCompare2DimArrayOfInt()");
     }

//-----------------------------------------------------------
   Print("\n\nUsing Global array: test_bwaShift2DimArrayOfInt():");
   Print("ArraySize(glbArr1) : ",(ArraySize(glbArr1)));
   Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
   ArrayCopy(glbArr1,testDataIn,0,0,WHOLE_ARRAY);

   bSuccess=bwaShift2DimArrayOfInt(glbArr1,5,2);
   if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
   else
     {
      bSuccess=bwaCompare2DimArrayOfInt(glbArr1,testDataOut,5,2);
      if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
      else Print("Test Passed: bwaCompare2DimArrayOfInt()");
     }
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   testTryPassByRef(); // Passed
   ///test_glbShift2DimArrayOfInt();
   test_bwaShift2DimArrayOfInt();
   Print("Leaving Oninit()\n\n");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   static bool bFirstRun = true;
   
   if( bFirstRun )
   {
      Print("Entering OnTick() First Run...\n");
      
      test_glbShift2DimArrayOfInt();
      Print("\nLeaving OnTick() First Run...\n");
   }
   bFirstRun = false;
  }
//+------------------------------------------------------------------+
Output:

Code: Select all

13:28:22 Testb625ArraySize test started
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: testTryPassByRef() results: 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ix: 5, dy: 5.1, az[ix-1]: 4.0
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ---
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 

Using Dynamic array: test_bwaShift2DimArrayOfInt():
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(localDynArr1) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(testDataIn) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Two dimensions: 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArrayRange: dim1 = 5, dim2 = 2 

13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: :   maxsize: 0, dim1: 2, dim2: 2
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ERROR ArraySize returned Zero!
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 

Using Local Static array: test_bwaShift2DimArrayOfInt():
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(localStaticArr1) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(testDataIn) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Two dimensions: 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArrayRange: dim1 = 5, dim2 = 2 

13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: :   maxsize: 0, dim1: 2, dim2: 2
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ERROR ArraySize returned Zero!
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 

Using Global array: test_bwaShift2DimArrayOfInt():
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(glbArr1) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(testDataIn) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Two dimensions: 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArrayRange: dim1 = 5, dim2 = 2 

13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: :   maxsize: 0, dim1: 2, dim2: 2
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ERROR ArraySize returned Zero!
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Leaving Oninit()


13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Entering OnTick() First Run...

13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 

Test using GLOBAL array:
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 

Using Dynamic array: test_glbShift2DimArrayOfInt():
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(localDynArr1) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArraySize(glbTestDataIn) : 10
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Two dimensions: 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ArrayRange: dim1 = 5, dim2 = 2 

13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0 
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: :   maxsize: 0, dim1: 2, dim2: 2
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: ERROR ArraySize returned Zero!
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: Test Failed: [glb] testbwaShift2DimArrayOfInt()
13:28:22 2014.03.03 00:00  Testb625ArraySize EURUSD,M1: 
Leaving OnTick() First Run...
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Empty4 v600 for Coders

Post by snailbeard »

Work around for two dimensional array returning ArraySize zero:

The work around that I have is unsatisfactory because it works for

Code: Select all

int& myArr[][]
whereas I was hoping I could use the same type used for ArraySize()

Code: Select all

int ArraySize( const void & anArray[] )
but that is a declaration type unavailable to end users.

So I would require a bodge for each varient of array declarations which would be too messy.

I am now wondering if I can take the improved code back to build 509!
hubinio
Posts: 1
Joined: Thu Apr 10, 2014 3:06 pm

Empty4 v600 for Coders

Post by hubinio »

have some additional information about porting to build v600:

had a big problem with:

iOpen(0,0,1)

worked well in the previous build

so i tried:

iOpen(StringConcatenate(0),0,1)

and it compiled with no error and no warnings but it only works with:

iOpen(NULL,0,1)

hope this helps somebody
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Empty4 v600 for Coders

Post by Radar »

Hey Snailbeard,
snailbeard » Fri Apr 11, 2014 1:33 am wrote:Work around for two dimensional array returning ArraySize zero:

The work around that I have is unsatisfactory because it works for

Code: Select all

int& myArr[][]
whereas I was hoping I could use the same type used for ArraySize()

Code: Select all

int ArraySize( const void & anArray[] )
but that is a declaration type unavailable to end users.

So I would require a bodge for each varient of array declarations which would be too messy.

I am now wondering if I can take the improved code back to build 509!
Got caught by the ampersand placement bug, eh? Some things work with the ampersand prepended to the variable name, and others don't. At least everything works when the ampersand is appended to the data type :)

As for the requirement to have different variants of the same function to handle arrays of different dimensions and/or types, you'll find the same requirement in C & C++, (and probably in microsoft's hashed C)... At least we can use function overloading now, so no need to have different function names for each :) Just a quick copy and paste, change the data type and dimensions, and "Job done!" (Well, you might have to change a few bits in the body of the function) :)

I'll probably get taken out the back and shot for this, but the changes to the language are a great improvement! They should have built-in 100% backward compatability in the compiler, though, with a warning that support for v509 code will cease within 12 months.

Try working with dynamic arrays in C, or C++... You have to manage each array's memory consumption, using malloc, realloc, and either dealloc or free, whenever you want to resize them, and you have to pass the number of elements, plus the size of the data-type to any function that manipulates any arrays, or the data within them :)

There seems to be a lot going on under the hood to make mql4 easier to learn and use than a full-blown programming language, but we don't realize it until we branch out to other languages.

Anyroad, gotta go... Too much blood in my coffeestream ;)

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Empty4 v600 for Coders

Post by snailbeard »

Hey Radar,

I thought you were onto something there, but I just tried moving the ampersands and it does not appear to change the result (which is consistent with C++).
:tears:

Perhaps if I reboot several times and stand on my head while drinking a glass of water it will start working as expected :lol:

Anyone who can get this updated example to do the right thing (or a simple workaround) will have my undying respect or a free pint of ale whichever is worth more :D

Code: Select all

 //+------------------------------------------------------------------+
        //|                                            Testb625ArraySize.mq4 |
        //|                                                       Snailbeard |
        //|                                                                  |
        //+------------------------------------------------------------------+
        #property copyright "Snailbeard"
        #property link      ""
        #property version   "1.00"
        #property strict
         
        #define IntToStr IntegerToString
         
        int glbArr1[5][2];
         
        int glbTestDataIn[5][2]=
          {
           11,12,
           21,13,
           31,14,
           41,15,
           51,16
          };
         
        int glbTestDataOut[5][2]=
          {
           0,0,
           11,12,
           21,13,
           31,14,
           41,15
          };
        //+------------------------------------------------------------------+
        //|                                                                  |
        //+------------------------------------------------------------------+
        void forceAppExit()
          {
        /*
           int a = 1;
           int b = 0;
           int c = a/b; // force divide by zero
           */
           ExpertRemove();
          }
        //+------------------------------------------------------------------+
        //|                                                                  |
        //+------------------------------------------------------------------+
        void tryPassByRef(int& x,double& y,double& z[])
          {
           double offset=0.1;
           int count=0;
         
           int iSizeOfZ=0;
         
           iSizeOfZ=ArraySize(z);
           if(iSizeOfZ<1)
             {
              Print("testPassByRef(): iSizeOfZ < 1: ");
              Print("ERROR z[] Array size is wrong!");
              forceAppExit();
              return;
             }
         
           for(count=0; count<10; count++)
             {
              if(count>=ArraySize(z))
                 break;
         
              z[count]=count;
             }
           x  = count;
           y  = offset + count;
          }
        //+------------------------------------------------------------------+
        //|                                                                  |
        //+------------------------------------------------------------------+
        void testTryPassByRef()
          {
           int ix=0;
           double dy=0.0;
           double az[5];
         
           tryPassByRef(ix,dy,az);
           Print("testTryPassByRef() results: ");
           Print("ix: ",ix,", dy: ",dy,", az[ix-1]: ",(az[(ix-1)]));
           Print("---");
         
          }
        //+------------------------------------------------------------------+
        //| bwaShift2DimArrayOfInt()                                                       |
        //+------------------------------------------------------------------+
        bool bwaShift2DimArrayOfInt(int& arrData[][], int dim1,int dim2)
          {
         
           Print("Two dimensions: ");
           int iDim0=ArrayRange(arrData,0);
           int iDim1=ArrayRange(arrData,1);
           
           PrintFormat("ArrayRange: iDim0 = %d, iDim1 = %d \n", iDim0, iDim1);
             
           int maxsize=ArraySize(arrData);
           if( maxsize == 0 )
           {
              Print("bwaShift2DimArrayOfInt(): maxsize == 0 ");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              Print("ERROR ArraySize returned Zero!");
              forceAppExit();
              return(false);
           
           }
           else if((dim1*dim2)>maxsize)
             {
              Print("bwaShift2DimArrayOfInt(): (dim1 * dim2) > maxsize: ");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              Print("ERROR Array size is wrong!");
              forceAppExit();
              return(false);
             }
           else {
              Print("bwaShift2DimArrayOfInt(): ");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              Print("SUCCESS ArraySize() returned POSITIVE INT!");
             }
         
           for(int i1=0; i1<dim1; i1++)
             {
              int rIdxLast = dim1  - 1 -  i1;
              int rIdxPrev = rIdxLast - 1;
              if(rIdxPrev<0)
                 break;
         
              for(int i2=0; i2<dim2; i2++)
                {
                 arrData[rIdxLast][i2]=arrData[rIdxPrev][i2];
                 if(rIdxPrev==0) arrData[0][i2]=0;
                }
             }
           return(true);
          }
        //+------------------------------------------------------------------+
        //| bwaCompare2DimArrayOfInt()                                                       |
        //+------------------------------------------------------------------+
        bool bwaCompare2DimArrayOfInt(int& arrData[][],int& arrData2[][], int dim1,int dim2)
          {
           bool bSuccess= true;
           bool bReport = false;
         
           int maxsize=ArraySize(arrData);
           if( maxsize == 0 )
           {
              Print("bwaShift2DimArrayOfInt(): maxsize == 0 ");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              Print("ERROR ArraySize returned Zero!");
              forceAppExit();
              return(false);
           }
           else if((dim1*dim2)>maxsize)
             {
              Print("bwaCompare2DimArrayOfInt() : Array arrData[][] dimension error!");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              return(false);
             }
           int size2=ArraySize(arrData2);
           if((dim1*dim2)>size2)
             {
              Print("bwaCompare2DimArrayOfInt() : Array arrData2[][] dimension error!");
              Print(":   maxsize: ",maxsize,", dim1: ",dim1,", dim2: ",dim2);
              return(false);
             }
           int i1 = 0;
           int i2 = 0;
           for(i1 = 0; i1 < dim1; i1++ )
             {
              int rIdxLast=dim1-1-i1;
         
              for(i2=0; i2<dim2; i2++)
                {
                 if(arrData[rIdxLast][i2]!=arrData2[rIdxLast][i2])
                   {
                    bSuccess=false;
                    if(bReport)
                      {
                       Print("bwaCompare2DimArrayOfInt() : Arrays are different!!!");
                       Print("index: "
                             +IntToStr(rIdxLast)+", "
                             +IntToStr(i2)+" : arrData: "
                             +IntToStr(arrData[rIdxLast][i2])+", "+", arrData2 : "
                             +IntToStr(arrData2[rIdxLast][i2]));
                      }
                   }
                }
             }
           Print("bwaCompare2DimArrayOfInt(): No. of Ints compared: ["
                 +IntToStr(i1)+"], ["
                 +IntToStr(i2)+"]");
           if((bSuccess==false) && (bReport==true))
              for(i1=0; i1<dim1; i1++)
                 for(i2=0; i2<dim2; i2++)
                    Print("index: "
                          +IntToStr(i1)+", "
                          +IntToStr(i2)+" : arrData: "
                          +IntToStr(arrData[i1][i2])+", "+", arrData2 : "
                          +IntToStr(arrData2[i1][i2]));
         
           return(bSuccess);
          }
        //+------------------------------------------------------------------+
        //| testbwaShift2DimArrayOfDoubles()                                                       |
        //+------------------------------------------------------------------+
        void test_glbShift2DimArrayOfInt()
          {
           Print("\n\nTest using GLOBAL array:");
         
        //-----------------------------------------------------------
           int localDynArr1[5][2];
           Print("\n\nUsing Dynamic array: test_glbShift2DimArrayOfInt():");
           Print("ArraySize(localDynArr1) : ",(ArraySize(localDynArr1)));
           Print("ArraySize(glbTestDataIn) : ",(ArraySize(glbTestDataIn)));
           ArrayCopy(localDynArr1,glbTestDataIn,0,0,WHOLE_ARRAY);
         
           bool bSuccess=bwaShift2DimArrayOfInt(localDynArr1,5,2);
           if(bSuccess==false) Print("Test Failed: [glb] testbwaShift2DimArrayOfInt()");
           else
             {
              bSuccess=bwaCompare2DimArrayOfInt(localDynArr1,glbTestDataOut,5,2);
              if(bSuccess==false) Print("Test Failed: [glb] bwaCompare2DimArrayOfInt()");
              else Print("Test Passed: [glb] bwaCompare2DimArrayOfInt()");
             }
          }
        //+------------------------------------------------------------------+
        //| testbwaShift2DimArrayOfDoubles()                                                       |
        //+------------------------------------------------------------------+
        void test_bwaShift2DimArrayOfInt()
          {
           static int testDataIn[5][2]=
             {
              11,12,
              21,13,
              31,14,
              41,15,
              51,16
             };
         
           static int testDataOut[5][2]=
             {
              0,0,
              11,12,
              21,13,
              31,14,
              41,15
             };
         
        //-----------------------------------------------------------
           int localDynArr1[5][2];
           Print("\n\nUsing Dynamic array: test_bwaShift2DimArrayOfInt():");
           Print("ArraySize(localDynArr1) : ",(ArraySize(localDynArr1)));
           Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
           ArrayCopy(localDynArr1,testDataIn,0,0,WHOLE_ARRAY);
         
           bool bSuccess=bwaShift2DimArrayOfInt(localDynArr1,5,2);
           if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
           else
             {
              bSuccess=bwaCompare2DimArrayOfInt(localDynArr1,testDataOut,5,2);
              if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
              else Print("Test Passed: bwaCompare2DimArrayOfInt()");
             }
         
        //-----------------------------------------------------------
        /// Test again with static array
           static int localStaticArr1[5][2];
           Print("\n\nUsing Local Static array: test_bwaShift2DimArrayOfInt():");
           Print("ArraySize(localStaticArr1) : ",(ArraySize(localStaticArr1)));
           Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
           ArrayCopy(localStaticArr1,testDataIn,0,0,WHOLE_ARRAY);
         
           bSuccess=bwaShift2DimArrayOfInt(localStaticArr1,5,2);
           if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
           else
             {
              bSuccess=bwaCompare2DimArrayOfInt(localStaticArr1,testDataOut,5,2);
              if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
              else Print("Test Passed: bwaCompare2DimArrayOfInt()");
             }
         
        //-----------------------------------------------------------
           Print("\n\nUsing Global array: test_bwaShift2DimArrayOfInt():");
           Print("ArraySize(glbArr1) : ",(ArraySize(glbArr1)));
           Print("ArraySize(testDataIn) : ",(ArraySize(testDataIn)));
           ArrayCopy(glbArr1,testDataIn,0,0,WHOLE_ARRAY);
         
           bSuccess=bwaShift2DimArrayOfInt(glbArr1,5,2);
           if(bSuccess==false) Print("Test Failed: testbwaShift2DimArrayOfInt()");
           else
             {
              bSuccess=bwaCompare2DimArrayOfInt(glbArr1,testDataOut,5,2);
              if(bSuccess==false) Print("Test Failed: bwaCompare2DimArrayOfInt()");
              else Print("Test Passed: bwaCompare2DimArrayOfInt()");
             }
          }
        //+------------------------------------------------------------------+
        //| Expert initialization function                                   |
        //+------------------------------------------------------------------+
        int OnInit()
          {
        //---
           testTryPassByRef(); // Passed
           ///test_glbShift2DimArrayOfInt();
           test_bwaShift2DimArrayOfInt();
           Print("Leaving Oninit()\n\n");
        //---
           return(INIT_SUCCEEDED);
          }
        //+------------------------------------------------------------------+
        //| Expert deinitialization function                                 |
        //+------------------------------------------------------------------+
        void OnDeinit(const int reason)
          {
        //---
         
          }
        //+------------------------------------------------------------------+
        //| Expert tick function                                             |
        //+------------------------------------------------------------------+
        void OnTick()
          {
        //---
           static bool bFirstRun = true;
           
           if( bFirstRun )
           {
              Print("Entering OnTick() First Run...\n");
             
              test_glbShift2DimArrayOfInt();
              Print("\nLeaving OnTick() First Run...\n");
           }
           bFirstRun = false;
          }
        //+------------------------------------------------------------------+
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Empty4 v600 for Coders

Post by snailbeard »

Compiling on both Build 625 and Build 509

This works by not using any new features of 600+ in the inculde files.

I have one top level MQ4 for each compiler and all the real work is now in MQH files.

The 625 ex4 is currently of no use because of the ArraySize() issue.

The 509 build which tries to use a (509) Lib on 625 platform never finds the Lib (tried putting copies of the (509) Lib in multiple directories but that did not help)

A 625 ex4 does find a 625 built Lib as expected.

To run the 509 ex4 on 625 it'll be necessary to include the library source into a single 509 ex4.
Then I'll know if the ArrarySize() issue is still a problem or not on 625.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Empty4 v600 for Coders

Post by snailbeard »

Joy is often short lived, but finally something to smile about, even if it is temporary:

I can finally run the EA on platform build 625 without any more rewriting:

The output from the Build 509 compiler does not manifest the ArraySize() issue:

Code: Select all

10:09:10 Expert zzbb_mt4b509: loaded successfully
10:09:10 TestGenerator: spread set to 20
10:09:12 zzbb_mt4b509 test started
10:09:15 2014.02.04 11:08  zzbb_mt4b509 EURUSD,M1: init(): About to call: ReportPointsAndSpreads()...
10:09:15 2014.02.04 11:08  zzbb_mt4b509 EURUSD,M1: EURUSD UAC:Buy(Y):Sell(Y):Risk:1.0 %;  Sp: 2.00,  Sp(Avg): 0.00,  HS: 2.00,  LS: 2.00,  LSw: -0.10,  SSw: -1.00,  
10:09:15 2014.02.04 11:08  zzbb_mt4b509 EURUSD,M1: bwaCompare2DimArrayOfInt(): No. of Ints compared: [5], [2]
10:09:15 2014.02.04 11:08  zzbb_mt4b509 EURUSD,M1: Test Passed: testbwaShift2DimArrayOfInt()
:D
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

ArraySize() of two-dimensional array passed by reference alw

Post by snailbeard »

Update on: ArraySize() of two-dimensional array passed by reference always returns zero.

I have had no news on this issue and I compiled and ran the test script on MetaQuotes Empty4 4 build 646 and I still get the same result as before.
genaja
Trader
Posts: 52
Joined: Wed Mar 21, 2012 12:42 pm

return value of 'OrderSend' should be checked

Post by genaja »

Hi volks,

I have a smal problem with a multiple buy script. The tree buy orders produces a warning:

Code: Select all

"return value of 'OrderSend' should be checked"
Any Ideas what I can do?

Code: Select all

//+------------------------------------------------------------------+
//|                                                 Buy_DAX_3_OP.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, eninefx."
#property link      "http://www.kaskus.us/showthread.php?t=3967467&page=350"

//versi 2.0 - 25-mei-2010

//munculkan parameter input
#property show_inputs

#include <stderror.mqh>
#include <stdlib.mqh>

//parameternya ini, input-nya ini
extern double  LOT             = 1;
extern double  TP              = 10.0;                
extern double  SL              = 10.0;                

double Poin;
//+------------------------------------------------------------------+
//| Custom initialization function                                   |
//+------------------------------------------------------------------+
int init(){

   if (Point == 0.00001) Poin = 0.0001;
   else {
      if (Point == 0.001) Poin = 0.01;
      else Poin = Point;
   }
   return(0);
}
//+------------------------------------------------------------------+
//                                                                   +
//+------------------------------------------------------------------+
int start()
  {  
   RefreshRates();
   while( IsTradeContextBusy() ) { Sleep(100); }
//----
   int ticket=OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+TP*Poin,"DAX_tripple1",1,0,CLR_NONE);
              OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+20.0*Poin,"DAX_tripple2",2,0,CLR_NONE);
              OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+60.0*Poin,"DAX_tripple3",3,0,CLR_NONE);

   if(ticket<1)
     {
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return(0);
     }
//----
   OrderPrint();
   return(0);
  }

User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

return value of 'OrderSend' should be checked

Post by milanese »

genaja » Mon Jun 02, 2014 7:46 am wrote:Hi volks,

I have a smal problem with a multiple buy script. The tree buy orders produces a warning:

Code: Select all

"return value of 'OrderSend' should be checked"
Any Ideas what I can do?

Code: Select all

//+------------------------------------------------------------------+
//|                                                 Buy_DAX_3_OP.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, eninefx."
#property link      "http://www.kaskus.us/showthread.php?t=3967467&page=350"

//versi 2.0 - 25-mei-2010

//munculkan parameter input
#property show_inputs

#include <stderror.mqh>
#include <stdlib.mqh>

//parameternya ini, input-nya ini
extern double  LOT             = 1;
extern double  TP              = 10.0;                
extern double  SL              = 10.0;                

double Poin;
//+------------------------------------------------------------------+
//| Custom initialization function                                   |
//+------------------------------------------------------------------+
int init(){

   if (Point == 0.00001) Poin = 0.0001;
   else {
      if (Point == 0.001) Poin = 0.01;
      else Poin = Point;
   }
   return(0);
}
//+------------------------------------------------------------------+
//                                                                   +
//+------------------------------------------------------------------+
int start()
  {  
   RefreshRates();
   while( IsTradeContextBusy() ) { Sleep(100); }
//----
   int ticket=OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+TP*Poin,"DAX_tripple1",1,0,CLR_NONE);
              OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+20.0*Poin,"DAX_tripple2",2,0,CLR_NONE);
              OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+60.0*Poin,"DAX_tripple3",3,0,CLR_NONE);

   if(ticket<1)
     {
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return(0);
     }
//----
   OrderPrint();
   return(0);
  }

you can ignore it, as it is only a warning, if you want remove the warning just change

Code: Select all

 bool ticket1=OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SL*Poin,Ask+20.0*Poin,"DAX_tripple2",2,0,CLR_NONE);
ecc...
Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Post Reply

Return to “Coders Hangout”