I need Help with Trailing Stop MQL5

 

Hello. I have a problem with the Trailing Stop. I have opened this article several times but I have not been able to solve my doubt.

I don't really want them to change all of my code, I just want to add something to what I already have.

When I do my Trailing Stop it starts from 0. That is, if I put a Trailing Stop of 10 and the operation reaches 10 and does not pass but returns to 0, the EA closes the operation. What I want is for the Trailing Stop to start from 10 pips gained and not from 0.


I leave my code. I don't want to change all the code since I'm familiar with it, I just want to add that.


   double TakeProfit= 5 ;
   double StopLoss= 5 ;
   double TrailingStop= 1 ;
   

   double Ask= SymbolInfoDouble ( _Symbol , SYMBOL_ASK );
   double Bid= SymbolInfoDouble ( _Symbol , SYMBOL_BID );

   double MyPoint= _Point ;
   if ( _Digits == 3 || _Digits == 5 )
      MyPoint= _Point * 10 ;
   double TheStopLoss= 0 ;
   double TheTakeProfit= 0 ;
   if (TotalOrdersCount()== 0 )

       MqlRates PriceArray();  

int posTotal= PositionsTotal ();
   for ( int posIndex=posTotal- 1 ; posIndex>= 0 ; posIndex--)
     {
       ulong ticket= PositionGetTicket (posIndex);
       if ( PositionSelectByTicket (ticket) && PositionGetInteger ( POSITION_MAGIC )==MagicNumber)
        {
         if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY )
           {
             if (TrailingStop> 0 )
              {
               if ( SymbolInfoDouble ( _Symbol , SYMBOL_BID )- PositionGetDouble ( POSITION_PRICE_OPEN )>MyPoint*TrailingStop)
                 {
                   if ( PositionGetDouble ( POSITION_SL )< SymbolInfoDouble ( _Symbol , SYMBOL_BID )-MyPoint*TrailingStop)
                    {
                     trade.PositionModify(ticket, SymbolInfoDouble ( _Symbol , SYMBOL_BID )-MyPoint*TrailingStop, PositionGetDouble ( POSITION_TP ));
                     return ;
                    }
                 }
              }
           }

         if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_SELL )
           {
                         if (( iHigh ( _Symbol , PERIOD_CURRENT , 1 ))) //here is your close buy rule
         {
         trade.PositionClose(ticket);
         break ;
         }
             if (TrailingStop> 0 )
              {
               if ( PositionGetDouble ( POSITION_PRICE_OPEN )- SymbolInfoDouble ( _Symbol , SYMBOL_ASK )>MyPoint*TrailingStop)
                 {
                   if ( PositionGetDouble ( POSITION_SL )> SymbolInfoDouble ( _Symbol , SYMBOL_ASK )+MyPoint*TrailingStop)
                    {
                     trade.PositionModify(ticket, SymbolInfoDouble ( _Symbol , SYMBOL_ASK )+MyPoint*TrailingStop, PositionGetDouble ( POSITION_TP ));
                     return ;
                    }
                 }
              }
           }
        }
     }