# 2 dimensional Arrays and frequency counters

2397

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 ?

2327

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.
2397

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

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 ?

2327

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]++

2397

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.