English

How to create rank function for some values? Need Help

 63 metropolis 2008.10.20 07:08   Anybody can help me how to create rank function for example I have some double value's like theese: a=3.0; b=4.0; c=5.0; d=2.0; e=1.0; f=6.0; g=0.0; from higher to lower value (6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0) or the value of (f,c,b,a,d,e,g) So the rank's should be like this rank number: (th) f=1 ; c=2; b=3; a=4; d=5; e=6; g=7; What I need is a function that return the rank if I input the value int rank (double value) { process all value's; return (the rank of a value from all value's) } I know it is easy if we just make a function like this for example value of "a" int rank (double value) { if(a>b && a>c && a>d && a>e && a>f && a>g) return (1); if( (ac && a>d && a>e && a>f && a>g)|| (ab && a>d && a>e && a>f && a>g)|| (ab && a>c && a>e && a>f && a>g)|| (ab && a>c && a>d && a>f && a>g)|| (ab && a>c && a>d && a>e && a>g)|| (ab && a>c && a>d && a>e && a>f) ) return (2); . . . . if(a
 1 tradersyoung 2008.12.10 20:54 #   metropolis: Anybody can help me how to create rank function for example I have some double value's like theese: a=3.0; b=4.0; c=5.0; d=2.0; e=1.0; f=6.0; g=0.0; from higher to lower value (6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0) or the value of (f,c,b,a,d,e,g) So the rank's should be like this rank number: (th) f=1 ; c=2; b=3; a=4; d=5; e=6; g=7; What I need is a function that return the rank if I input the value int rank (double value) { process all value's; return (the rank of a value from all value's) } HI Use the following function RankArray I include an example of how to use it by calling from a dummy indicator ------------------------------------------------------------------ //Example of using RankArray routine #property copyright "TraderSYoung" int start() {return(0);} int deinit() {return(0);} int init() { double A1[]={3.1,6.7,5.2,1.005,2.002,3.5,4.77,4.78}; int Ranked[1]; for (int i=0;i
 2 marcomania 2014.06.28 08:04 #   hello TradersYoung and Metropolis, I understand you have deal with problem long time ago - i am facing the same issure and I found your coding very useful to understand how MT4 handles ranking. I had a quesiton for your. what is the meaning of this part of the code "&Ranked[]". What I am not clear is what this piece of function differs from "Ranked[]".as you can undestand I am a newbe, but catching up fast with this matter - I am a trader learning how to code....and kind of starting from scratchappreaciate your quick input to shed some light on the matter.Best, MM
 747 honest_knave 2014.06.28 10:26 #   By using the ampersand (&) you are explicitly passing the array by reference .
13116
WHRoeder 2014.06.28 14:27 #

tradersyoung: Use the following function RankArray
1.  Play video Please edit your post. For large amounts of code, attach it.

2. Also you can just calculate the rank on the fly
```double A1[]={3.1,6.7,5.2,1.005,2.002,3.5,4.77,4.78};
Print("Rank of A1[2]=="+DoubleToStr(A1[2])+" is "+Rank(A1,A1[2]);
:
int Rank(double arr[], double value, int mode=MODE_ASCEND){
int dir  = mode == MODE_ASCEND ? +1 : -1;
int rank = 0;
for(int iArr = ArraySize() - 1; iArr >= 0; --iArr)
if( (value - Arr[iArr])*dir >= 0) ++rank;
return rank;
}```

 762 Boeing747 2014.06.28 16:54 #   ```     double x[]={2.0, 1.0, 6.0, 3.0, 0.0, 5.0, 4.0};      double s;      int e;      int size=ArraySize(x);         for(int n=0; nx[i])               {                s=x[i];                e=i;               }            }          x[e]=x[n];          x[n]=s;         }    Alert(x[0],x[1],x[2],x[3],x[4],x[5],x[6]);``````   string w[]={"E","c","f","b","j","R","A","H","a","c"};    int size=ArraySize(w);    string abc[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};    string ABC[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};    int c,e,i;    for(i=0; i<26; i++)      {       for(e=c; e
 52 debar 2014.06.28 22:03 #   In case you only require the index of the min max value in the array: https://docs.mql4.com/array/arraymaximumhttps://docs.mql4.com/array/arrayminimum