Limit number of trades

 

   Dear programmers,

    How can I limit for example to open only a trade or a limit to 2 trades?

     int notrades=2;

     int total=OrdersTotal();

    while(total<notrades)

    OrderSend(...)

    notrades++;

  but it opens more than 2...  maybe becaus the if condition is always true as the ordersend positions are closed by takeprofit parameter or ?

   

 
if(OrdersTotal()<2)
 {
  OrderSend(....
 }
 

Marco vd Heijden: I want to open when ask is lower than one of ibands but it opened a lot of them because it is true the condition and I want to limit this to open only 2 not all time when is lower. Should I check something else ?

 

 
should I put the condition inside my open trade function and to have two conditions for opening ? limit order and ask is lower then ibands?
 

You have to set a flag once the order is open nd then filter that one too.

 
Marco vd Heijden:

You have to set a flag once the order is open nd then filter that one too.

give me a code example please, flag I know but I don t understand filter that one too

 
Marius Ovidiu Sunzuiana:

give me 

Here are some examples

Reason: