|
Post by bobpit on May 2, 2016 9:40:54 GMT
I am trying to create an algorithm that will group price values, when they are close together. For example if I have the following list of prices : 0.85, 0.86, 0.89, 0.95, 1.9, 1.92, 1.923, 1.95, 3.4, 3.43, 3.46, 8.4, 15.2, 22.1, 22.14, 22.4, 35
I would like to create the following groups: group1: 0.85, 0.86, 0.89, 0.95 group2: 1.9, 1.92, 1.923, 1.95 group3: 3.4, 3.43, 3.46 group4: 22.1, 22.14, 22.4
After some googling I found this: Nearest neighbor search (https://en.wikipedia.org/wiki/Nearest_neighbor_search). Seems that this has to be solved like a mathematical problem and then I need to code it in AB.
While I am doing this, I thought to ask if anybody came across something similar and has a simpler solution.
|
|
pan
Rookie
Posts: 27
Received Likes: 2
|
Post by pan on May 2, 2016 21:33:42 GMT
Hi bob According to your last post about buttons my mind goes that you maybe looking something like this? Sorry if it is out of topic, but I was thinking to drop it here
// ---- Decimals //dec = (Param("Decimals",4,0,7,1)/10 )+1; // to Parameters Window
decN = pOrderType; switch( decN) { case "FOREX": dec =(4/10)+1; break; case "DECIMAL": dec= (2/10)+1; break; case "INTEGER": dec =1; break;
// etc. }
|
|
|
Post by bobpit on May 2, 2016 22:04:38 GMT
Hi Pan
No, it is not related to my previous post. I believe the specifications I gave are clear enough.
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 3, 2016 13:01:55 GMT
|
|
|
Post by bobpit on May 3, 2016 13:06:47 GMT
andwilson
I don;t think this is related either.
All I want to do is group values that happen to be close together. Values that have no nearby neighbours, they are not grouped.
I thought this would be easy to explain and do.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 4, 2016 19:06:04 GMT
I am trying to create an algorithm that will group price values, when they are close together. For example if I have the following list of prices : 0.85, 0.86, 0.89, 0.95, 1.9, 1.92, 1.923, 1.95, 3.4, 3.43, 3.46, 8.4, 15.2, 22.1, 22.14, 22.4, 35 I would like to create the following groups: group1: 0.85, 0.86, 0.89, 0.95 group2: 1.9, 1.92, 1.923, 1.95 group3: 3.4, 3.43, 3.46 group4: 22.1, 22.14, 22.4 After some googling I found this: Nearest neighbor search (https://en.wikipedia.org/wiki/Nearest_neighbor_search). Seems that this has to be solved like a mathematical problem and then I need to code it in AB. While I am doing this, I thought to ask if anybody came across something similar and has a simpler solution. Here I've made a code suggestion amibrokerforum.proboards.com/thread/168/sort-values-integer-size
|
|
|
Post by bobpit on May 4, 2016 19:14:44 GMT
>>>> Here I've made a code suggestion <<<
I do not see the code. ie the commands that will create the different groups.
Maybe I can make it a little more clear?
This is the input: 0.85, 0.86, 0.89, 0.95, 1.9, 1.92, 1.923, 1.95, 3.4, 3.43, 3.46, 8.4, 15.2, 22.1, 22.14, 22.4, 35
The program should somehow group the values and create this output: group1: 0.85, 0.86, 0.89, 0.95 group2: 1.9, 1.92, 1.923, 1.95 group3: 3.4, 3.43, 3.46 group4: 22.1, 22.14, 22.4
Likewise ....
input #2: 2, 12. 35.1, 35.3, 36, 36.2, 54.3, 54.7, 56, 90
output #2: group1: 35.1, 35.3, 36, 36.2 group2: 54.3, 54.7, 56
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 4, 2016 19:35:23 GMT
>>>> Here I've made a code suggestion <<< I do not see the code. ie the commands that will create the different groups. The code is ATTACHED!
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 4, 2016 20:41:20 GMT
>>>> Here I've made a code suggestion <<< I do not see the code. ie the commands that will create the different groups. Maybe I can make it a little more clear? This is the input: 0.85, 0.86, 0.89, 0.95, 1.9, 1.92, 1.923, 1.95, 3.4, 3.43, 3.46, 8.4, 15.2, 22.1, 22.14, 22.4, 35 The program should somehow group the values and create this output: group1: 0.85, 0.86, 0.89, 0.95 group2: 1.9, 1.92, 1.923, 1.95 group3: 3.4, 3.43, 3.46 group4: 22.1, 22.14, 22.4 Likewise .... input #2: 2, 12. 35.1, 35.3, 36, 36.2, 54.3, 54.7, 56, 90 output #2: group1: 35.1, 35.3, 36, 36.2 group2: 54.3, 54.7, 56 Then simply change the "IsNull" column (three times) in my ATTACHED code. Do you get that done on your own or do you require another additional special hand holding?
|
|
|
Post by bobpit on May 4, 2016 20:47:01 GMT
aha! I had to click on the thumb-up to see the code. Thank you, I just downloaded it.
|
|