Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-23-2006, 11:49 AM
cubesteak's Avatar
Senior Member
 
Join Date: Jul 2006
Location: Southern California
Posts: 160
cubesteak is on a distinguished road
Lightbulb Code for you: array search helpers

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/mor...tions-for-mt4/

The library file can be found here:

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


To use this file, you'd simply:

Code:
#include <CSArrayFunctions.mq4>
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?


Last edited by cubesteak; 08-23-2006 at 12:08 PM.
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 09-02-2006, 12:28 AM
deeforex's Avatar
Member
 
Join Date: Oct 2005
Posts: 91
deeforex is on a distinguished road
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
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 09-04-2006, 03:50 AM
cubesteak's Avatar
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
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
  #4 (permalink)  
Old 09-04-2006, 05:55 AM
deeforex's Avatar
Member
 
Join Date: Oct 2005
Posts: 91
deeforex is on a distinguished road
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!
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

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
Trend /Reversal /Continuation HELPER cja Tools and utilities 195 09-23-2009 09:27 AM
Function that returns an Array? charliev Metatrader 4 23 11-19-2008 04:16 AM
Data in Array converted to btw 0 and 1 ( normalisation) ! icm63 Metatrader 4 4 01-22-2007 02:25 AM


All times are GMT. The time now is 09:33 AM.



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