sorting 2 dimensional array by second dimension - page 2

 

Hey Gordon, thanks for the heads up, while reading that code, i was reminded that I already have a code snippet that loops through the basket to find the biggest loser trade, I could use it coupled with a clone of it reversed to find the biggest winner, it winner is greater than loser, then I can close each one. That will work for what I need. Sometimes, just sleeping on it is the best code generator of them all. Shoot, I could probably code this over night. Not much of a modification. I fon't have to have them all close at once. We go through it the first time, then on next tick or candle we can go through it again, or like I was talking about before, I have another feature that fires at the same time that something like this would be handy. I can just embed it into that features coding.

Thank you for the eye opener Gordon.

 

If you want to sort the arrays by price, why don't you just load the price into the first dimension and the ticket into the second dimension......then you can sort it in the normal way.

 

Yes that was already thought of. Then just copy the the data to another array in inverted arrangement to sort back the other way. What I decided to do was much simpler and actually fit my needs much better. I basically loop through the open trades and find the largest winner and the largest loser that is less than the largest winner, then I close them both. On the next tick or candle, it repeats the process. Turned out just fine.

 
gordon:

Regardless of what u would like to call it, the first dimension in a 2D array is the vector arr_name[0,1,...,n][0], so technically the first bracket holds the first dimension; this is also the vector that will be sorted by ArraySort(). From the book:

As long as we are on the subject of ArraySort() I'll mention 2 undocumented peculiarities I have found over time (and would be happy if anybody confirms or corrects me...?):

  1. If some of the elements in the first dimension are identical, they won't necessarily retain their order. Obviously this should be documented if it's 'by-design', otherwise I would consider this to be a 'bug'.
  2. OrderSort() does not work with 4D arrays (returns error 4053). Again, this should be documented but it's not.
Sorry for the belated response fellas.. many things got in the way.. I assure you I most appreciate your responses.
FWIW these are my responses (in 'spammy' mode :( ) :
- On 1D arrays no question arises. On 2D, 3D, 4D arrays the left-most pair of bracket is always the first-dimension is that correct gordon?
 
cameofx:
- On 1D arrays no question arises. On 2D, 3D, 4D arrays the left-most pair of bracket is always the first-dimension is that correct gordon?

Yes.

 
gordon:

Regardless of what u would like to call it, the first dimension in a 2D array is the vector arr_name[0,1,...,n][0], so technically the first bracket holds the first dimension; this is also the vector that will be sorted by ArraySort(). From the book:

As long as we are on the subject of ArraySort() I'll mention 2 undocumented peculiarities I have found over time (and would be happy if anybody confirms or corrects me...?):

  1. If some of the elements in the first dimension are identical, they won't necessarily retain their order. Obviously this should be documented if it's 'by-design', otherwise I would consider this to be a 'bug'.
  2. OrderSort() does not work with 4D arrays (returns error 4053). Again, this should be documented but it's not.
Sorry for the belated response fellas.. many things got in the way.. I assure you I most appreciate your responses.
FWIW these are my responses :
- On 1D array no question arises. On 2D, 3D, 4D arrays the left-most pair of bracket is always the first-dimension. This is my understanding too.
int    a[50];       // A one-dimensional array of 50 integers.
double m[7][50];    // Two-dimensional array of seven arrays,
                    //each of them consisting of 50 integers
but when I look at this explanation. The way it is described were "Two-dimensional array of seven arrays. each of them consisting of 50 integers" On contemplating this & your responses... This must
be an erroneous explanation because it suggests that the 50 integers are more like the row/member size of the data and 7 is the column/header. This led me to believe (erroneously)
the right-most was the row/member part we should/can conveniently resize..
- I appreciate you sharing your finding gordon. Unfortunately testing is a luxury for me these days... I can only get a hold of computer & internet intermittently (it's complicated).
Even testing on a dead chart proves to be a challenge... :( . Hence my sometimes 'twisted comprehension'. TBH, I mostly rely on memory & references...(sorry..).

PS : oops.. didn't know the former post got in. I edited it.
 
cameofx:
[...] This must be an erroneous explanation because it suggests that the 50 integers are more like the row/member size of the data and 7 is the column/header.

I am not sure what it suggests, but regardless, the left-most is the first dimension. A lot of the documentation is a translation from Russian, many times not a very good translation, so maybe this is one of those cases. The column/row thing is just a metaphor; it makes it easier for us to imagine the array, but has nothing to do with the actual implementation. Whether the first dimension is a 'row' or a 'column' is up to u...

 
1005phillip:


I look at array indexing and dimensioning in the standard spreadsheet manner...Row-Column (mnemonic "Roman-Catholic").

1D Array: MyArray[RowNumber-1]

2D Array: MyArray[RowNumber-1][ColumnNumber-1]

3D Array: MyArray[RowNumber-1][ColumnNumber-1][Worksheet-1] ....

These are the way I pictured it too. the reference I quoted regarding first-dimension threw me off..(see above post). So we logically cannot resize the ColumnNumber and/or WorksheetNumber
and/or BookNumber..only the RowNumber. Which is the left-most pair of bracket in 2D, 3D & 4D arrays.
 
cameofx:
So we logically cannot resize [...]

That's right.

 
gordon:

I am not sure what it suggests, but regardless, the left-most is the first dimension. A lot of the documentation is a translation from Russian, many times not a very good translation, so maybe this is one of those cases. The column/row thing is just a metaphor; it makes it easier for us to imagine the array, but has nothing to do with the actual implementation. Whether the first dimension is a 'row' or a 'column' is up to u...

yep.. unfortunately, many of us - I'm sure I'm speaking for many newbs out there.. - relies much too often on existing documentation..

Reason: