Array search helper functions for your use...

 

Hey y'all.

Been programming recently, and was frustrated at how limiting and silly array searches are in MT4.

So, I wrote some new ones. One for searching a single dim array, and one for searching a 2 dimensional array.

I think they're kinda neat - maybe you will too.

Also, in the file are 2 array "printing" functions for use during development or for EA comments, etc. Again, one for 1 dim array and 1 for 2 dim array.

Basically they just print out a string representation of the arrays to the Experts tab of the Terminal.

More info here:

http://www.cubesteak.net/2006/08/more-array-functions-for-mt4/

The library file can be found here:

http://www.cubesteak.net/downloads/CSArrayFunctions.zip

To use this file, you'd simply:

#include

in whatever file you'd like to use them from.

I'd love to hear how this could be improved, how you like or dislike it, etc...

Comments? Criticism? Witty sayings?

 

Hi Cubesteak,

I'm a coding newbie doing a search for arrays and don't know how to use your file.

What I'm trying to do is catalog the given values for all of the open orders....such as OrderOpenPrice(), OrderProfits(), OrderLots(), etc. From this catalog of info I would like to search it for the maximum and minimum values and then be able to identifiy it by ticket. Also how would I go about sorting it, to execute commands to close out the ones with highest profits first, etc.

Thanks in Advance,

dee

 
deeforex:
Hi Cubesteak,

I'm a coding newbie doing a search for arrays and don't know how to use your file.

What I'm trying to do is catalog the given values for all of the open orders....such as OrderOpenPrice(), OrderProfits(), OrderLots(), etc. From this catalog of info I would like to search it for the maximum and minimum values and then be able to identifiy it by ticket. Also how would I go about sorting it, to execute commands to close out the ones with highest profits first, etc.

Thanks in Advance,

dee

Hi Dee,

You can certainly do this with an array. I would recommend a 2 dimensional array. MyOrders[][n], where n is the actual number of pieces of information you would like to store. (meaning, if you want to store Open price, profits and lots, that would be MyOrders[][4]).

Your first dimension can either be blank, or can be a unique ID, like ticket number,etc. Why use a blank first dimension? I donno - it just gives something to iterate by, so I tend to keep all my info in the second dimension, and leave the first one blank. Up to you though...

There is a function called:

int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)

That will pick the minimum, and

int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

will pick the maximum. Of course, these are just for single dimension arrays.

To get around that, you could do the following... Say you want to pick the order with the most profit, and close it.

Simply create a for loop that iterates through your 2 dimensional array, and places all the "profit" values into a new temporary single dimension array, say MyTempArray[]. As long as you place your profit values into MyTempArray[] in the same order as they are in MyOrders[][], the position returned from ArrayMaximum(MyTempArray) will give you the same position as the correct order in the first dimension of MyOrders[][].

There may be an easier way to do this, but I can't think of one off the top of my head.

Let me know how you do! I'd be glad to offer more guidance if you can't find a better alternative.

Cheers,

CS

 

Thanks Cubesteak for getting back to me. I was trying to do a 2 dimensional array but was not successful. CodersGuru has offered to write such a snippet for me since it will be of generic use. In the meantime, I'm hunkering down with a C++ book and trying to absorb the section on arrays.

thanks again!

 
cubesteak:

Hey y'all.

Been programming recently, and was frustrated at how limiting and silly array searches are in MT4.

So, I wrote some new ones. One for searching a single dim array, and one for searching a 2 dimensional array.

I think they're kinda neat - maybe you will too.

Also, in the file are 2 array "printing" functions for use during development or for EA comments, etc. Again, one for 1 dim array and 1 for 2 dim array.

Basically they just print out a string representation of the arrays to the Experts tab of the Terminal.

More info here:

http://www.cubesteak.net/2006/08/more-array-functions-for-mt4/

The library file can be found here:

http://www.cubesteak.net/downloads/CSArrayFunctions.zip

To use this file, you'd simply:

#include

in whatever file you'd like to use them from.

I'd love to hear how this could be improved, how you like or dislike it, etc...

Comments? Criticism? Witty sayings?

Hi cubesteak, do you still have the code? Cause it seem not found on the site anymore.

Reason: