Forex Factory
  • Login

  • Username: Password:
  • 2:33am

  • Search
  • Home

  • Forums

  • Trades

  • Calendar

  • News

  • Market

  • Brokers

Options

Search

Subscribe to Thread

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

Similar Threads

orderselect problem 1 reply

comment() 5 replies

Can't get OrderSelect() to find order automatically 2 replies

OrderSelect() Index Problem 3 replies

Any Comment?? 5 replies

  • Platform Tech
  • /
  • Reply to Thread

OrderSelect by comment

  • Post# 1
  • Quote
  • First Post: Jul 20, 2008 1:14am
  • Postrock
    Joined Mar 2008 | 169 Posts | Status: Member
I'm halfway thru the coding of a simple, fully functional EA. But i'm still just a newbie in coding.
I just cant figure out how to make my EA select all orders that have a specific comment and perform an action on those only.

For example i may have 3 open orders each commented "whatever comment 1" and another two commented "whatever comment 2".
How can i make my EA select only the first "whatever comment 1" order group and perform an action on those 3?

For what i have red in documentations on the MQL4 site there is no clue on how OrderSelect can do such a thing.
Sorry if this is a stupid question..i guess one has to start somewhere if he wants to get a grip on coding..
  • Post# 2
  • Quote
  • Jul 20, 2008 1:21am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
There is a function called "OrderComment()".

So, OrderSelect();

if (OrderMagicNumber == MagicNumber && OrderComment() = "Comment #1")

etc.
  • Post# 3
  • Quote
  • Jul 20, 2008 1:32am
  • Postrock
    Joined Mar 2008 | 169 Posts | Status: Member
thx Ron..
i had seen that. but i'm confused on the use i should do of OrderSelect..since it only can select by position or ticket. How do i select all the open and pending orders and then filter out with OrderComment..

should i just pile on 10 different bits of code like
Orderselect by position 0 if comment so do this else do that
Orderselect by position 1 if comment so do this else do that
Orderselect by position 2 if comment so do this else do that
Orderselect by position 3 if comment so do this else do that
Orderselect by position 4 if comment so do this else do that
  • Post# 4
  • Quote
  • Jul 20, 2008 2:15am
  • Craig
    Joined Feb 2006 | 1,378 Posts | Status: Blah blah blah
int num_orders = OrdersTotal();
for(int i = 0; i < num_orders; i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_T RADES)==false)
{
break;
}
if (OrderComment() == "Blah")
{
//Do something
}
}
The breaking of a wave cannot explain the whole sea.
  • Post# 5
  • Quote
  • Jul 20, 2008 3:48am
  • Zen_Leow
    Joined Jun 2008 | 607 Posts | Status: Programming for a better future.
Quoting Postrock
thx Ron..
i had seen that. but i'm confused on the use i should do of OrderSelect..since it only can select by position or ticket. How do i select all the open and pending orders and then filter out with OrderComment..

should i just pile on 10 different bits of code like
Orderselect by position 0 if comment so do this else do that
Orderselect by position 1 if comment so do this else do that
Orderselect by position 2 if comment so do this else do that
Orderselect by position 3 if comment so do this else do that
Orderselect by position 4 if comment so do this else do that
what you can do, or rather what you should always do is loop thru all your current positions, pending and/or opened lies in the same list. I hope you're using Magic Number as well. if you're just going to find the trades opened by your EA, Magic Number comparison is the way to go. you should use OrderComment comparison only if your EA actually writes different comments for different trading situations and you wanna have it to have different actions for such cases.

Inserted Code
   int total = OrdersTotal();
   if (total > 0)
   {
      for(int cnt=0;cnt<total;cnt++)
      {
         if(OrderSelect(cnt,SELECT_BY_POS))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM) // this checks for the orders opened by your EA
            {
               if (OrderComment() == "Whatever your 1st type of comment is") // compare the commenting
               {
                  // do what you want.
               }
               if (OrderComment() == "Whatever your 2nd type of comment is") // compare the commenting
               {
                  // do what you want.
               }
               if (OrderComment() == "Whatever your 3rd type of comment is") // compare the commenting
               {
                  // do what you want.
               }
            }
         }
      }
   }
  • Post# 6
  • Quote
  • Last Post: Jul 20, 2008 8:55am | Edited at 9:18am
  • Postrock
    Joined Mar 2008 | 169 Posts | Status: Member
great responses!
Thank you guys..

I'll check magic number. I just need an efficient way to properly recognize one or more orders out of the list and do proper action. Once i could implement one in my EA i can experiment with different methods.
Thread Tools Search this Thread
Show Printable Version Show Printable Version
Email This Thread Email This Thread
Search this Thread:

Advanced Search

  • Platform Tech
  • /
  • OrderSelect by comment
  • Reply to Thread
0 traders viewing now

©2013 Forex Factory, Inc. / Terms of Use / Privacy Policy

Forex Factory® is a registered trademark.

Connect

  • Facebook
  • Twitter
  • RSS

Company

  • About FF
  • FF Blog
  • Careers at FF
  • Advertising
  • Contact FF

Products

  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer

Website

  • Homepage
  • Search
  • User Guide
  • Member List
  • Online Now
  • Report a Bug