Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 10-20-2008, 03:50 AM
primajaya's Avatar
Senior Member
 
Join Date: Aug 2006
Posts: 213
primajaya is on a distinguished road
How to create rank function for some value's? Need Help

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(a<b && a<c && a<d && a<e && a<f && a<g)
return(7);
}

The Problem is when the variations of value are 2 the combination only a few, but when the variations increase for example 5,7 or 10 etc so the combination to make the rank will very very a lot..

Hope somebody can help me for this kind of problem..

Thank's berfore, Sorry for my poor english, but I'm learning..
Pj..
__________________
You said "why?".. I said "why not?!"
Broker for 5$ Free
Trading system 4free
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-11-2008, 03:29 PM
Junior Member
 
Join Date: Nov 2008
Posts: 3
Zen_Leow is on a distinguished road
if you place your values in an array then sort the array in descending order using ArraySort function, the index of the array + 1 is will be the rank.

Code:
  int rank (double value)
  {
     double All_Values[] = {3.0,4.0,5.0,2.0,1.0,6.0,0.0};
     ArraySort(All_Values,WHOLE_ARRAY,0,MODE_DESCEND);
     // The above 2 lines probably should be elsewhere and set as global variables
     for (int i=0; i<ArraySize(All_Values); i++)
     {
        if (All_Values[i] == value)
        {
           return (i+1);
        }
     }
     return (0);
  }
hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 12-10-2008, 06:09 PM
Junior Member
 
Join Date: Sep 2008
Posts: 3
tradersyoung is on a distinguished road
Rank Array Function - Generic

Quote:
Originally Posted by primajaya View Post
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)
}


Pj..
This is a useful function to have around. I always intended to write a generic function for this, so here goes.

I am assuming you have an array with some values, but you want to keep the original array in the same order. I have created a function
RankArrray() that will return an array that points to the original array in ranked order. Default is descending order, ascending is option.

Since I choose not to change the original array, I return the result in an Array "Rank[], each value of which is the index of the value in the Input Array in ranked order.


As written the original input array must be single dimension, if you have an array with more than one dimension you need to modify the function or copy to a single dimension array first.

I include an example of how to test it and how to use the RankArray to point to the original in rank order. Drop the example in your expert folder, complile and attach to a chart - examine the experts log.

Try it out and see how it works.


//+-------------------------------------------------------------
void RankArray(double InputArray[], int &Ranked[], bool sort_descending=true) {

//Purpose: Input: an array with a set of numbers that have been calculated in some fashion
// Output is array Ranked[] such that
// Ranked[0] points to the first member of the InputArray[]
// i.e. InputArray[Ranked[0]] is highest value
// InputArray[Ranked[1]] is next highest, ect.
// InputArray[] is unchanged
// sort_descending optional, default value true - is for Descending Order
// false will sort in ascending order
// User can modify as necessary for two dimensional Arrays.

int InputArraySize=ArrayRange(InputArray,0);

// Create Temporary array to sort - with pointers to original element
double TempArray[1][2];
ArrayResize(TempArray,InputArraySize);

for (int i=0;i<InputArraySize;i++)
{TempArray[i][0]=InputArray[i];
TempArray[i][1]=i;
}

int sort_dir;
//Validate input values
if (!sort_descending) sort_dir=MODE_ASCEND;
else sort_dir=MODE_DESCEND;

//Sort the Array-first element only
ArraySort(TempArray,WHOLE_ARRAY,0,sort_dir);

//Create output array - ranked by pointing to orignal values in ranked order
ArrayResize(Ranked,InputArraySize);
for (i=0;i<InputArraySize;i++)
{Ranked[i]=TempArray[i][1];}
return;
}
Attached Files
File Type: mq4 test sort.mq4 (2.0 KB, 5 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to create EA please fxwealth Expert Advisors - Metatrader 4 9 04-06-2009 11:09 PM
FlyingDutchManSystem (How Create EA) forexart Expert Advisors - Metatrader 4 33 04-08-2008 03:46 AM
RCI (Rank Correlation Index) fxhst329 Indicators - Metatrader 4 0 09-12-2007 04:05 PM
Help me please to create an indicator frosk Indicators - Metatrader 4 0 02-06-2007 11:45 AM
Please create an EA matrixebiz Expert Advisors - Metatrader 4 0 11-28-2006 08:19 PM


All times are GMT. The time now is 07:17 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.