View Single Post
  #3 (permalink)  
Old 09-04-2006, 03:50 AM
cubesteak's Avatar
cubesteak cubesteak is offline
Senior Member
 
Join Date: Jul 2006
Location: Southern California
Posts: 160
cubesteak is on a distinguished road
Quote:
Originally Posted by 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
Reply With Quote