How to set Maximum number of Trades per currency pair for an EA.

 
Hello! Am a newbie. I just built an EA but it keeps opening hundreds of trades once the conditions are meant. How do I set the maximum number of trades. 
I want the EA to open only two positions per currency pair.
Any useful info will be appreciated.
 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. You don't. Check your open count before opening again. Or

  3. Check only once per bar. Or
              New candle - MQL4 programming forum 2014.04.04

  4. You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 17.12.12

Reason: