Limit number of trades

Marius Ovidiu Sunzuiana
2265

   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 ?

   

Marco vd Heijden
Moderator
13600
if(OrdersTotal()<2)
 {
  OrderSend(....
 }
Marius Ovidiu Sunzuiana
2265

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 ?

 

Marius Ovidiu Sunzuiana
2265
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?
Marco vd Heijden
Moderator
13600

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

Marius Ovidiu Sunzuiana
2265
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

Marco vd Heijden
Moderator
13600
Marius Ovidiu Sunzuiana:

give me 

Here are some examples