how to make sure ea accesses only certain trades?

 
I use OrderSelect(i,SELECT_BY_POS) to select the trades with my EA. But it affects all my trades, and I want it to affect only a few, certain trades. How can I make it work only on those certain trades, any ideas?
 

u can use OrderMagicNumber() for example

 
hondaissace:
I use OrderSelect(i,SELECT_BY_POS) to select the trades with my EA. But it affects all my trades, and I want it to affect only a few, certain trades. How can I make it work only on those certain trades, any ideas?
Select your trades using OrderSymbol()  . . . .  if your EA is on multiple timeframes of the same symbol then you will need to use a Magic Number
 
bool    MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
    if (!OrderSelect(iWhat, eSelect, ePool)    ) return (false);
    if (OrderMagicNumber() != magic.number     ) return (false);
    if (OrderSymbol()      != analyze.pair     ) return (false);
    if (ePool != MODE_HISTORY                  ) return (true);
    return(OrderType() <= OP_SELL); // Avoid cr/bal forum.mql4.com/32363#325360
                                    // https://forum.mql4.com/30708
                                    // Never select canceled orders.
}
//
for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if (MySelect(iPos, SELECT_BY_POS)){
  :
 
WHRoeder:


Thanks for the reply, can you elaborate what  "return(OrderType() <= OP_SELL);" is for? Why the "<" sign? Also there are supposed to be else between those ifs? Thanks for replying.
 
  1. can you elaborate what  "return(OrderType() <= OP_SELL);" is for
    what part of
    Avoid cr/bal
    and
    Never select canceled orders.
    was unclear? Canceled means deleted Pending orders.

  2. also there are supposed to be else between those ifs?
    Why would there be any else's? If you return your gone. An IF() A else B; means you do A or B, AND THEN what ever follows. IF(){ A; return;} else B; means you're going to do A and return, or B AND whatever follows, which is the same as IF(){ A; return; } B. Simplify your code. Never use an else after a return, break, or continue. Never use IF(){A} else{B return } use IF(!..){B return } A
 
WHRoeder:
  1. can you elaborate what  "return(OrderType() <= OP_SELL);" is for
    what part of
    andwas unclear? Canceled means deleted Pending orders.

  2. also there are supposed to be else between those ifs?
    Why would there be any else's? If you return your gone. An IF() A else B; means you do A or B, AND THEN what ever follows. IF(){ A; return;} else B; means you're going to do A and return, or B AND whatever follows, which is the same as IF(){ A; return; } B. Simplify your code. Never use an else after a return, break, or continue. Never use IF(){A} else{B return } use IF(!..){B return } A

cr/bal?
 

WHRoeder did post a URL linking to another post that contained:

 

 FYI, although not officially documented, these are the OrderType() of balance/credit statements when they are selected:

    1. 'Balance' statement: OrderType()==6
    2. 'Credit' statement: OrderType()==7
OrderType() <= OP_SELL

 helps weed 'em out 

And in any case, answer to the query for this post is at 

for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if (MySelect(iPos, SELECT_BY_POS))
 
OK I get it thanks to all of you man
Reason: