How to limit transactions on the same bar in Tester - ADX

 

I created my ADX EA that makes orders when current ADX crosses line 25 but the problem that I have is multi-orders when TP is set to 5 pips.
I am looking for a solution to stop EA in Tester for next 3 bars when TP was reached.

Thanks in advance for help.


 
static bool AllowBuy = true ;

if ( Buytrigger()==true && AllowBuy==true ) 
  {
   OpenBuy();
   AlowBuy=false ;
  } // no more buy trades until
  
if ( BuyTrigger()==false )
  { 
   AlowBuy=true ;
  }
 
GreenPoint: I am looking for a solution to stop EA in Tester for next 3 bars when TP was reached.
Why just in the tester?
int     MyOrdersTotal(){
    int count=0;
    for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--)
      if (MySelect(iPos, SELECT_BY_POS) count++;
    return(count);
}
bool    MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
    if (!OrderSelect(iWhat, eSelect, ePool)     return (false);
    if (OrderMagicNumber() !=  magic.number)    return (false);
    if (OrderSymbol()      != chart.symbol)     return (false);
    if (ePool != MODE_HISTORY)                  return (true);
    return(OrderType() <= OP_SELL); //Avoid cr/bal forum.mql4.com/32363#325360
                                    //Never select canceled orders.
}
int start(){
    static datetime BeginTrading;
    if (BeginTrading > Time[0]) return;                 // Not allowed yet.
    if (MyOrdersTotal() > 0){                           // Order(s) still open.
        BeginTrading = Time[0] + 3 * Period()*60;       // Stop for 3 bars.
        return; 
    }
    :
 
WHRoeder:
Why just in the tester?

Thanks WHRoeder. Code was missing two parentheses but it's GREAT.

I was looking for code that works in tester due to the fact that Sleep does not work.

Reason: