2 dimensional Arrays and frequency counters

Ian Venner
2397
Ian Venner  

I wonder if someone might help me with this problem

I understand how to make a 1 dimensional counter array to count the amount of something like

array[6]

array[OrderType()]++

would count the amount of orders of each type there are while in a order_by_pos checking loop

is it possible to make a 2 dimensional array where only the second index counts the frequence of something ?

where there are several orders which may have different magic numbers between 1 and 9

and I want to list in the array how many orders of each type have the same magic number at first I thought i could do it something like this

array[10][6]

array[MagicNumber][OrderType]++

then i realised although it would count how many orders of each type there are at the same time it would also increase the magic number index every time a new order is found

how would i create a counter that would work on the second index independantly from the first ?

gordon
2327
gordon  
SDC:

array[MagicNumber][OrderType]++

then i realised although it would count how many orders of each type there are at the same time it would also increase the magic number index every time a new order is found

No it wouldn't. It would work just fine. But note that in this case the possible magic numbers are 0,1,2,...,9.
Ian Venner
2397
Ian Venner  

Really ? Thanks Gordon I thought I had it wrong, there wouldnt be any entry in the zero index because my lowest magic number will be 1 that could be any order type though

so if I use:

array[MagicNumber][OrderType]++

considering

OP_BUY 0 Buying position.
OP_SELL 1 Selling position.
OP_BUYLIMIT 2 Buy limit pending position.
OP_SELLLIMIT 3 Sell limit pending position.
OP_BUYSTOP 4 Buy stop pending position.
OP_SELLSTOP 5 Sell stop pending position.

If I had 3 open buy orders all with magic number 4

and 2 pending Sell Limit orders both with the magic number 6

array[4,0] would hold the value 3 and array[6,3] would hold the value 2 ?

gordon
2327
gordon  
SDC:

If I had 3 open buy orders all with magic number 4

and 2 pending Sell Limit orders both with the magic number 6

array[4,0] would hold the value 3 and array[6,3] would hold the value 2 ?

Yes.


[...] there wouldnt be any entry in the zero index because my lowest magic number will be 1 [...]

You can do this:

array[MagicNumber-1][OrderType]++

Ian Venner
2397
Ian Venner  

Awesome !! thanks for your help Gordon I've been puzzling over that one for the past 2 hours I'll implement it like you said with the -1 I wouldnt have thought of that, now Ill be able to finish my order accounting function tonight.