Trailing stop not working

 

I wrote some code for a trailing stop with the help of a tutorial and it works as it should:

#include<Trade\Trade.mqh>

CTrade trade;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   
//--- Open test position
   if(PositionsTotal()==0)

      trade.Buy(0.10,NULL,Ask,(Ask-1000*_Point),0,NULL);

   CheckTrailingStop(Ask);
  }

//+------------------------------------------------------------------+
//| Trailing Stop Loss                                               |
//+------------------------------------------------------------------+
void CheckTrailingStop(double Ask)
  {

   double SL = NormalizeDouble(Ask-10*_Point,_Digits);

   for(int i =PositionsTotal()-1; i>=0; i--)
     {
      string symbol=PositionGetSymbol(i);
      if(_Symbol==symbol)
        {
         ulong PositionTicket=PositionGetInteger(POSITION_TICKET);
         double CurrentStopLoss=PositionGetDouble(POSITION_SL);
         if(CurrentStopLoss<SL)
            trade.PositionModify(PositionTicket,(CurrentStopLoss+1*_Point),0);
        }
     }
  }
//+------------------------------------------------------------------+

However when I insert it into the EA I'm developing it doesn't work at all, the orders show a stop loss being set but its not triggering when it should. I feel like the issue is that its getting caught up in the order of operations somewhere but I cant put my finger on it.

I attached my code instead of pasting it because its pretty long.

Any help would be appreciated!

Files:
SMAuto.mq5  39 kb
 
Neverminded, I figured it out. I didn't correctly set an initial stop loss on the order.
Reason: