Tester not triggering my stop loss and profit targets when hit

 

Hi, I have the following code below - it seems to work fine running live (don't worry, it's a non-profitable strategy) where the stop loss and profit targets are hit, but when I run it in Tester, it does not trigger then and instead just closes the position(s) on the very last data set. Do I need to program the EA to close the order if either my stop loss or profit target gets hit? I thought just passing them into OrderSend, that Tester would simulate it for me - or am I wrong on this? here's my code:


extern double BuyLots = 1;
extern int BuySlippage = 0;
extern int BuyStopLoss = 10;
extern int BuyTakeProfit = 5;

bool newBar = false;

double prevMa;
double openLots = 0;

int start() {
   // only run on the closing/formation of a bar
   newBar();
   if (newBar == false) return;
   
   double ma = iMA(NULL, 0, 9, 8, MODE_SMMA, PRICE_CLOSE, 1);
   
   if (prevMa != NULL) {
      
      openLots = 0;
      for (int cnt = 0; cnt < OrdersTotal(); cnt++) {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         
         if (OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
            openLots = openLots + OrderLots();
         }
      }
      
      if (openLots < 5) {
         if (ma < 0) {
            double slippage = NULL;
            if (BuySlippage > 0) slippage = BuySlippage;
            
            double stopLoss = NULL;
            if (BuyStopLoss > 40) {
               stopLoss = (Ask - (BuyStopLoss * Point));
            } else {
               stopLoss = (Ask - (40 * Point));
            }
            
            double takeProfit = NULL;
            if (BuyTakeProfit > 40) {
               takeProfit = (Ask + (BuyTakeProfit * Point));
            } else {
               takeProfit = (Ask + (40 * Point));
            }
            
            int ticket = OrderSend(Symbol(), OP_BUY, BuyLots, Ask, BuySlippage, stopLoss, takeProfit, "BUY triggered", 1234, 0, Green);
            
            if (ticket > 0) {
               if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                  Print("BUY order opened : ", OrderOpenPrice());
               }
            }
         }
      }
      
   }
   
   prevMa = ma;
   
   return(0);
}

void newBar() {
   static datetime newTime = 0;
   newBar = false;
   
   if (newTime != Time[0]) {
      newTime = Time[0];
      newBar = true;
   }
}
Reason: