Need some help in controlling the no of open positions?

 
Hi, I am building an expert advisor based on such a strategy that if i don't control the no of open positions,it opens a new trade on every single bar.What code should i add in my expert advisor so that i can control the no of trades and whenever i attach my ea on a chart,it asks for the maximum no of open positions along with lots,tp and sp....Thanx alot in advance !!!
 

You have to assign a miagc numbr to your trades.

And use some code you get how many trades have been opened. Something like that:

   for(int cnt=0;cnt<OrdersTotal();cnt++) 
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber() == MagicNumber)
      {
         TradesCount = TradesCount+1;
      }
   }
Then before you open any order you can check the TradesCount < {MAX NUMBER OF TRADES YOU WANT)
 

Apologies for my insufficient knowledge,but can you tell me where in my ea i should paste this code in order to control maximum no of open trades just like its shown in the attachment.....If any other code is used for the purpose shown in the attachment,then Please do let me know about that code !!!

 
i would be greatful to see an example myself. i'm not very good at making codes, so i don't really have and idea what to do with code pieces like the one codersguru gave, but if i had an example EA, i would probably be able to figure out how it really works :)
 

@ crashestdummy....well i hope you do.I downloaded this ea (the one in the picture) from http://www.platinumforexbot.com/free.htm ..If its not avalible anymore,then please do let me know.I'll attach my copy of ea in my next post if you wish.By the way,Best of luck :)

 

@innovativebug

if you can, please share the free ea and i'll check it out. i've visited the site and it looks like another one of those scam robots :) still, the order management may be used at building our own robots...