trade.PositionClose problem

 

Hi, I'm trying to open position when trend change and hold it until change again, as seen in photo below.

red dots mean sell , blue mean buy

//1 up / -1 down
   double trend = trendIndicator[0]; //current
   double trend2 = trendIndicator[1]; //prev trend

   
   if(trend == 1 && trend2 == -1)
     {
      if(PositionsTotal() > 0)
         closeAll();
      Order("buy","");
     }
   if(trend == -1 && trend2 == 1)
     {
      if(PositionsTotal() > 0)
         closeAll();
      Order("sell","");
     }

I tried like this but didn't successed. every hour it create 1 or -1 signal, if it change from 1 to -1 mean sell and if it change from -1 to 1 this mean buy. It work with constant tp and sl, but i want to hold it till trend change again.

With this code it only create first 2 order then it stop open new order.

Any help ?

Reason: