how to code this????

 

I wanna put magic number for buy order(include pending) and 1 for sell order.

so with this ea on in a pair, all order i send will have the magic number (either buy or sell).

example,

*magic number 111111 for buy, 222222 for sell.

*i on this ea at EU, i open a buy order at 1.4100, 4 buy stop at every +40pips with a sl 10pips and 4 buy limit at every -40pips with tp 40pips. at the same time i set sell order at 1.4100 and the same as above.

so if 1 of the buy order(after any 1 or more pending buy order are open) is close(hits tp or sl), the ea will close all the open and pending buy order(with magic number 111111), and all the sell order are still remain(magic number 222222).

can anyone help me to code this ea?

 

Why do you want to identify whether an order is a buy or sell by a query to OrderMagicNumber() ?

Why not just query OrderType() for OP_BUY or OP_SELL ?


CB

 
cloudbreaker wrote >>

Why do you want to identify whether an order is a buy or sell by a query to OrderMagicNumber() ?

Why not just query OrderType() for OP_BUY or OP_SELL ?

CB

cuz i dun know about coding, but if "query OrderType() for OP_BUY or OP_SELL". if i close 1 buy order by tp or sl or manual close, will it close for all other buy order including pending order.

i wan this is because i wanna open buy and sell together in the same chart.... and both order will run their own strategy to close it....

if u could help me to code this ea i can tell u to concept i wan.... lets discuss will it works....

 
howdanny:

if i close 1 buy order by tp or sl or manual close, will it close for all other buy order including pending order

Orders with TP or Sl are closed server side if TP or SL are reached. Manual close will close the specific order ticket u pass to OrderClose(), so no other orders will be closed. Pending orders cannot be 'closed', they can be deleted using OrderDelete() and again only the specific ticket u pass to the function will be deleted. See -> OrderClose(), OrderDelete()


i wan this is because i wanna open buy and sell together in the same chart.... and both order will run their own strategy to close it....

if u could help me to code this ea i can tell u to concept i wan.... lets discuss will it works....

Let's say u opened buy and sell and u want to close just one of them according to some criterion, then use something like this:


   for (int i = OrdersTotal()-1; i>=0; i--)              
      {
      if ( !OrderSelect(i, SELECT_BY_POS ) ) continue;     
      
      if ( OrderType() == OP_BUY )
         if ( // criterions for closing buy... )
            OrderClose( OrderTicket(),...,...)
            
      if ( OrderType() == OP_SELL )
         if ( // criterions for closing sell... )
            OrderClose( OrderTicket(),...,...)
      }
Reason: