Why divide an Array in half to 'resize it' after I have just entered the size of it with OrdersTotal( ) ?

 
I searched extensively for this and found lots with much more complicated issues than this, but I can't find and nor understand how and why dividing and array in half correctly 'resizes' it when I have just entered the count into the Array with
OrdersTotal( )
 
sorry but I really don't understand your question. Could you decorate it with some code examples?
 

The array you are looking at may not be applicable to all orders. I use this technique to resize an array where I am detecting the transition of a pending order to a trade. in this case I have an array that contains only pending order information. OrdersTotal() would be useless to me.

 
FourX:
I searched extensively for this and found lots with much more complicated issues than this, but I can't find and nor understand how and why dividing and array in half correctly 'resizes' it when I have just entered the count into the Array with
OrdersTotal( )
Where did u c this?
 
FourX:
I searched extensively for this and found lots with much more complicated issues than this, but I can't find and nor understand how and why dividing an array in half correctly 'resizes' it when I have just entered the count into the Array with
OrdersTotal( )

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int iTrades;

int iTradesTotal;
double dTrades[1][2];
double dTradesAscending;
double dTradesDescending;

/*

*/

iTradesTotal = OrdersTotal();

iTradesTotal = ArraySize(dTrades); // I usually subtract 1 from this:

// iTradesTotal = ArraySize(dTrades) - 1;

dTradesAscending = ArraySort(dTrades, WHOLE_ARRAY, 0, MODE_ASCEND);


for (int i = 0; i < dTradesAscending; i ++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())

//Note the first Boolean in the last line. This must be a typo/error and should be either '==' OR '!=' ?

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

But normally I find Arrays sized in the following manner throughout the code in here:

//---------------------------------------------------------------------------------

double BuyProfits [1][2];
double SellProfits [1][2];

/*

*/

Orders = ArraySize(BuyProfits) / 2;
for (Order = 0; Order < Orders; Order++)

//--------------------------------------------------------------------

This makes no sense to me. As far as I can see it would just end up making the array count 1/2 of what it should be and actually is?

Also in all such instances I see no code, evidence etc of any data actually being entered into the Array as I have done in my example. So I don't understand how they are getting the data into the Array either?

I don't understand why they are using 2 dimensional arrays in such instances when they are only using one dimension in each Array for the trade price. etc

Thanks Guys! . (< 8)

________________________________________-

FYI: The 'b', 'i', d', 's'. in front of the Variables is a convention that I use as Cloud Breaker uses and suggested to me. I find it beneficial as It is immediately indicative of what type of data it is. I even use 'dnVariable for a normalized double and dnaVariable for a 'normalized double array' etc

 

ArraySize() returns the count of elements contained in the array. Since the 2nd dimension has a fixed size of 2, it would return twice the amount of elements in the first dimension. In other words, the following holds:

int arr[x][y];   //y>=1

// no matter how many times we use ArrayResize(), the following is still true:
ArraySize(arr)/y == ArrayRange(arr,0);  // true
 
gordon:

ArraySize() returns the count of elements contained in the array. Since the 2nd dimension has a fixed size of 2, it would return twice the amount of elements in the first dimension. In other words, the following holds:

HI Gordon,

I figured that I was trying to utilize ArraySize to enter the data into it when it only OutPuts the count / size of an existing array.

I don't know why the second array would always have to be '2' though? A chess or checker board is an example of a 2 dimensional array, and obviously has more than one or two rows and columns in both the first and second array elements, When the array is first declared /stipulated, one often sees MyArray [1][2]. Is this just defining it as a two dimensional array or do the numbers in the square brackets set the number of element in that array dimension? If so, then an array declared initially as YourArray[3][5] would have 4 * 6 = 24 (including the zeros) unique elements in it? I don't believe that this IS the case, but trying to get it ALL straight in my mind and be sure I do understand everything about them correctly.

Looking at the documentation, the only Array function that I see that actually 'sets'' the array size is 'ArrayRange', then subtracting one from such arrays as they start at zero and not one.

Otherwise the Array sizes are 'dynamic' and are automatically resized to suit the quantity of data being entered into them ?

Do I have this correct now?

As always, thanks for your help, it IS greatly appreciated! (< 8)

 
FourX:

I don't know why the second array would always have to be '2' though?

I didn't say that... That's the way it is in your example.

[...] When the array is first declared /stipulated, one often sees MyArray [1][2]. Is this just defining it as a two dimensional array or do the numbers in the square brackets set the number of element in that array dimension? If so, then an array declared initially as YourArray[3][5] would have 4 * 6 = 24 (including the zeros) unique elements in it? I don't believe that this IS the case, but trying to get it ALL straight in my mind and be sure I do understand everything about them correctly.

These questions are too fundamental, please do some reading -> https://book.mql4.com/variables/arrays.

Looking at the documentation, the only Array function that I see that actually 'sets'' the array size is 'ArrayRange' [...]

No.

Otherwise the Array sizes are 'dynamic' and are automatically resized to suit the quantity of data being entered into them ?

No.