Trailing Stoploss is Invaid Stop

 

Sir,

I am using Multi-Symbol...

It has one found "Failed Modify this Stoploss (Invalid Stop)" but It has working to modified this Stoploss is too many times .

Please see this attached photo..

//Input
input group "Trailing Start & Step, Stop :- "
input bool TrailingStart_Step_Stop = true;
input int Trail_start = 10;
input int Trail_Step = 5;
input int Trail_stop = 5;


// Trailing Point
double Trail_start_point;
double Trail_Step_point;
double Trail_stop_point;

int OnInit()
  {
//Digits
   int digits = 1;
   if(Digits() == 3 || Digits() == 5)
     {
      digits = 10;
      point = Point() * digits;
     }
   else
      if(Digits() <= 2 || Digits() == 4)
        {
         digits = 10;
         point = Point() * 1;
        }


//Trailing Start,Step,Stop
   Trail_start_point = Trail_start * point;
   Trail_Step_point = Trail_Step * point;
   Trail_stop_point = Trail_stop * point;


//---
   return(INIT_SUCCEEDED);

  }


//I am using System Function..
bool Modify_Trail(string Symbol_Param, ulong Position_Ticket, double modify_TP, double modify_SL)
  {
   MqlTradeRequest Modifyrequest = {};
   MqlTradeResult Modifyresult = {};

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

   ENUM_POSITION_TYPE Pos_type = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);
   double Pos_entry = PositionGetDouble(POSITION_PRICE_OPEN);
   double Pos_Volume = PositionGetDouble(POSITION_VOLUME);

   Modifyrequest.symbol = Symbol_Param;
   Modifyrequest.action = TRADE_ACTION_SLTP;
   Modifyrequest.position = Position_Ticket;
   Modifyrequest.volume = Pos_Volume;
   Modifyrequest.sl = modify_SL;
   Modifyrequest.tp = modify_TP;

   if(!MyOrderSend(Modifyrequest, Modifyresult))
     {
      Print("Modify Trailing is Failed");
      return false;
     }

   return true;
  }


void Trailing_Sta_Ste_Stop(string Symbol_Trail, double TStart, double TStep, double TStop)
  {
   for(int i = PositionsTotal() - 1; i >= 0; i--)
     {
      ulong ticket = PositionGetTicket(i);
        {
         string Check_Symbol = PositionGetString(POSITION_SYMBOL);
         
         if(PositionSelectByTicket(ticket) && Check_Symbol == Symbol_Trail)
           {
            double Position_TP = PositionGetDouble(POSITION_TP);
            double Position_Open_Price = PositionGetDouble(POSITION_PRICE_OPEN);
            double Position_SL = PositionGetDouble(POSITION_SL);

            long Position_Ticket = PositionGetInteger(POSITION_TICKET);

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

            bool r ;
            double Stop_level = SymbolInfoInteger(Symbol_Trail, SYMBOL_TRADE_STOPS_LEVEL) * point;
            double trail = MathMax(TStop, Stop_level); // Minimum Stoplevel

            double TSstart = TStart ;
            double jump = MathMax(TStep, Point()) ;

            double TSL_Buy = NormalizeDouble(Bid - trail,Digits());
            double TSL_Sell = NormalizeDouble(Ask + trail,Digits());

            ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);
            string Check_Symbol = PositionGetString(POSITION_SYMBOL);


            if(Position_Type == POSITION_TYPE_BUY)
              {
               //Trailing Start,Step,Stop
               if(Trail_stop != 0 && TSL_Buy - Position_Open_Price >= TSstart && Position_SL + jump <= TSL_Buy)
                 {
                  r = Modify_Trail(Symbol_Trail, ticket, Position_TP, TSL_Buy);

                  if(!r)
                    {
                     Print("Price = ", Position_Open_Price,", Buy Order Trailing Stop Loss is Modify Failed");
                    }
                  else
                    {
                     Print("Buy Order Trailing Stop Loss is Modified ");
                    }
                 }

              }


            if(Position_Type == POSITION_TYPE_SELL )
              {
               //Trailing Start,Step,Stop
               if(Trail_stop != 0 && Position_Open_Price - TSL_Sell >= TSstart && (Position_SL - jump >= TSL_Sell /*|| Position_SL == 0 */))
                 {
                  r = Modify_Trail(Symbol_Trail, ticket, Position_TP, TSL_Sell);

                  if(!r)
                    {
                     Print("Price = ", Position_Open_Price,", Sell Order Trailing Stop Loss is Modify Failed");
                    }
                  else
                    {
                     Print("Sell Order Trailing Stop Loss is Modified ");
                    }
                 }
              }

           }
        }
     }

  }
Files: