No trailingstop, even if it's been set up

 
Hello guys, I have a problem.. According to the logic, regarding the position ticketTL, the ea should move the trailingstop up. Instead, it remains a fixed stoploss. No errors in the journal.
//+------------------------------------------------------------------+ 
//|                                                  Momentum_v1.mq4 | 
//|                                                             Skox | 
//|                                                                  | 
//+------------------------------------------------------------------+ 
#property copyright "Skox" 
#property link      "" 
#property indicator_separate_window 

double Punto; 
extern bool DisplayInfo=true; 
extern string    S1 ="Lotti da aprire, minimo 0.02 "; 
extern double Lotti=0.02; 
extern string    S2 ="Numero posizioni massime. Minimo 2"; 
extern int NPosMax=2; 
extern double TrailingStop=15; 

int TF,i; 
string cmt; 
int New_Bar; 
bool NoTradeFlag; 
datetime Time_0; 


extern int MagicNumber=987569; 
//+------------------------------------------------------------------+ 
//| expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int init() 
  { 
Time_0=Time[0]; 

// Compatibility wiht 3,4,5 digits prices 
    
   if(Digits>=4) Punto = 0.0001; 
   else Punto = 0.01; 

//----Gestione TimeFrame, =1 fino a 4h, =2 oltre 
if (Period()<=240) TF=1; 
else TF=2; 
  } 
//+------------------------------------------------------------------+ 
//| expert deinitialization function                                 | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 
//---- 
    
//---- 
   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| expert start function                                            | 
//+------------------------------------------------------------------+ 
int start() 
{ 
 //---Stampa informazioni su CHART 
   void PrintInfo; 
   { 
   bool setupBAR; 
   string cmt=""; 
      cmt = "========================"; 
      cmt =  cmt + "\nAccount Name: [ " + AccountName() + " ]";             
      cmt =  cmt + "\nAccount Leverage: [ " + DoubleToStr( AccountLeverage(), 0 ) + " ]";       
      cmt =  cmt + "\nMin Lot: [ " + DoubleToStr( MarketInfo(Symbol(),MODE_MINLOT), 3 ) + " ]";       
      cmt =  cmt + "\nLot Step: [ " + DoubleToStr( MarketInfo(Symbol(),MODE_LOTSTEP), 3 ) + " ]";       
      cmt =  cmt + "\nCurrent Profit: [ " + DoubleToStr(AccountEquity()-AccountBalance(),2) + " ]"; 
      cmt =  cmt + "\nAccount Balance: [ " + DoubleToStr(AccountBalance(),2) + " ]"; 
      cmt =  cmt + "\nAccount Equity: [ " + DoubleToStr(AccountEquity(),2) + " ]";       
      cmt =  cmt + "\nSetup Bar exist?:  " + setupBAR + " "; 
      cmt =  cmt + "\n========================"; 
      Comment(cmt); 
      } 

//---Indicatori       
   double Atr=iATR(NULL,0,20,0); 
   double fastMA=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0); 
   double slowMA=iMA(NULL,0,40,0,MODE_SMA,PRICE_CLOSE,0); 
   double Adx=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0); 

//---Funzione Buffer 
  double buffer; 
  if (TF==1) buffer=2*Punto; 
  else buffer=0.001*Close[0]; 
   
//---Controlla se è nata una nuova candela 
  New_Bar=0;                                            
    if (Time_0 != Time[0])                                   
      { 
      New_Bar = 1;  
      NoTradeFlag=false;                                              
      Time_0 = Time[0];  
      } 
    
    
//--- Se setup bar esiste setupBAR=true, altrimenti false   

   if (Low[1]>fastMA && Low[1]>slowMA && Close[1]>Open[1] && Close[1]>(High[1]-Low[1])*0.7 && High[1]<High[iHighest(Symbol(),0,MODE_HIGH,5,1)] && (Close[1]-Open[1])<1.5*Atr && Adx>25)  
     {setupBAR = true;} 
   else{setupBAR = false;} 

//--- Se il targetprofit non viene raggiunto entro 5 candele, la posizione si chiude al close della 5°   
   double prezzo; 
   datetime open= OrderOpenTime(); 
    
   if(OrderType()==OP_BUY) prezzo=Ask; 
   else prezzo=Bid; 
    
//---Gestione stoploss. Prima di piazzarlo in reale ricordarsi di cambiare 10 pips con MarketInfo(Symbol(),MODE_STOPLEVEL) 
   double StopLoss; 
   if(Close[1]-(Low[1]-buffer)<10*Punto) 
   {StopLoss=Low[1]-10*Punto;} 
   else StopLoss=(Low[1]-buffer); 


//--- Controllo numero ordini 
   double Spread=Bid-Ask; 
   int ordtot=OrdersTotal(); 
   int ticket, ticketTL; 
//---Gestione TrailingStop. La variabile TrailingStop è external. Trailing è il nuovo livello di stoploss per ordini con trailingstop  
   double TSTP=TrailingStop*Punto; 
   double Trailing; 
   if (OrderType() == OP_BUY) 
       { 
         if ((Bid - OrderOpenPrice()) > TSTP) 
         { 
            if (OrderStopLoss() < (Bid - TSTP)) 
            { 
              Trailing=Bid-TSTP; 
            } 
            else 
            { 
              Trailing=OrderStopLoss(); 
            }   
         } 
       } 
      else if (OrderType() == OP_SELL) 
       { 
         if ((OrderOpenPrice() - Ask) > TSTP) 
           { 
              if ((OrderStopLoss() > (Ask + TSTP)) || (OrderStopLoss() == 0)) 
                { 
                  Trailing=Ask+TSTP; 
                } 
           } 
       } 
   
  
//---Gestione ordini e modifica di trailingstop e targetprofit  
   if(ordtot<NPosMax) 
   { 
    if (setupBAR==true && NoTradeFlag==false) 
     { 
       ticket=OrderSend(Symbol(),OP_BUY,Lotti/2,prezzo,3,StopLoss,prezzo+Atr,"Momentum Method",MagicNumber,0); 
          OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); 
            if (ordtot>=1) 
               { 
                  if(OrderTicket()==ticket) 
                    {  
                      if (prezzo>(OrderOpenPrice()+Spread))  
                        { 
                           OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+Spread,OrderTakeProfit(),0,Green); 
                        } 
                    }     
               } 
       ticketTL=OrderSend(Symbol(),OP_BUY,Lotti/2,prezzo,3,StopLoss,0,"Momentum Method",MagicNumber,0); 
          OrderSelect(ticketTL,SELECT_BY_TICKET,MODE_TRADES); 
             if (ordtot>=1) 
                { 
                  if(OrderTicket()==ticketTL) 
                        { 
                           if(prezzo>(OrderOpenPrice()+Spread+Trailing)) 
                              { 
                              OrderModify(ticketTL,OrderOpenPrice(),prezzo-Trailing,OrderTakeProfit(),0,Green); 
                              } 
                        } 
  
               }  
    } 
  } 
 }  
 
       ticket=OrderSend(Symbol(),OP_BUY,Lotti/2,prezzo,3,StopLoss,prezzo+Atr,"Momentum Method",MagicNumber,0); 
          OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); 
            if (ordtot>=1) 
               { 
                  if(OrderTicket()==ticket) 
                    {  
                      if (prezzo>(OrderOpenPrice()+Spread))  
                        { 
                           OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+Spread,OrderTakeProfit(),0,Green); 
                        } 
                    }     
               } 

Did this fail ???

You open the trade and directly you trie to get no loss this always fails

 
  1. ,OP_BUY,Lotti/2,prezzo,3
    You can't just divide by 2. The amount must be a multiple of lotstep and at least minlot. See my reply to your other question.
  2. What is prezzo, you can ONLY open a buy at the ASK.
  3. EA's must adjust for 4/5 digit brokers, tp, sl, AND slippage. On ECN brokers you must open first and then set stops.
  4. Always test your return codes
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
           Alert("OrderModify failed: ", GetLastError());
         */
    

  5. if the ordersend worked AND the orderSelect worked, when would this not be true?
    if(OrderTicket()==ticket) 

  6. OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+Spread,OrderTakeProfit(),0,Green);
    You opened at the ASK. Now the market is at the Bid (BELOW the orderOpenPrice.) Do you really expect to be able to set a stop ABOVE market (at the Bid + 2*spread)
Reason: