BuyStop/SellStop not expiring in Strategy Tester

 

Hi there! I´m coding an EA that should place a BuyStop / SellStop order at a specific price and if it doesn't reach this price it should be cancelled after 2 bars (10 min since im using it on M5 timeframe).

I tried to do that by setting an expiration time but when I test it on the strategy tester it doesn't expire and the order stays forever, even though it displays the right time when I print the 'expiration ' value

Here is the code I'm using:

if (
      NewBar
      && !bIspending
      && !posAberta 
      && rates[4].close>rates[4].open       
      && rates[3].close>rates[3].open     
      && rates[3].close >= EMA9Array[3]   
      && rates[3].close>=rates[4].high    
      && rates[1].close<rates[1].open     
      )
      
      {
       // entry price
       if (rates[1].high>rates[2].high)
          {PRC = NormalizarPreco(rates[1].high);}
       else 
          {PRC = NormalizarPreco(rates[2].high);}
      
       // SL & TP & Lots & Expiration
       TKP = NormalizarPreco(PRC + ((takeprofit * ATRarray[1])/100.0) ); 
       STL = NormalizarPreco(PRC - ((SLPercent * TKP)/100.0));
       double lots = calcLots(PRC-STL);
       Expiration= TimeCurrent()+600;
       
       // Ordem
       trade.BuyStop(lots,PRC,_Symbol,STL,TKP,ORDER_TIME_SPECIFIED,Expiration);
     //  trade.Buy(lots, _Symbol, PRC, STL, TKP, "" );
       bAtivacaoCompra = true;
       beAtivo = false;
     
       }


Can anyone guess what i might be doing wrong?
Is there any other way I can make this order to be cancelled after 2 bars?

Thanks in advance!

 

Hi

Maybe you have some problems within trade Buystop function, and this feature does not place expiration correctly or perhaps you use some wrong parameters here. Can you show use the code f this function?

Best regards