Trail stop stops moving

 

Let say  we have 2 conditions for trailing: Trail with 300000 points at a defined signal. Else trail 100000 points if previous trade was a loss using martingale.

We have 2 Open Positions at 0.2 lots on diff pairs (Boom1000 and Boom500 and Boom500 hits Sl. On candle open, Boom500 a position with 0.4 and trails with 100000. Now the issue that I have is when the other Boom1000 hits Tp the Trail stop for the Boom500 stops wherever it is and whenever Boom1000 hits take profit

//+------------------------------------------------------------------+
//|          Signal                                                  |
//+------------------------------------------------------------------+
if(glSignal == SIGNAL_BUY && (co[3] > cc[3] &&co[2] < cc[2] &&cc[1] > cc[2] && co[1] < cc[0] &&cc[3] < co[1]  && co[0] > cc[3]) &&
   Positions.Buy(Magic_Number) == 0)
  {
   if(glSellTicket > 0)
     {
      Trade.Close(glSellTicket);
     }

   glBuyTicket = Trade.Buy(_Symbol,tradeSize);

   if(glBuyTicket > 0)
     {
      double openPrice = PositionOpenPrice(glBuyTicket);

      double buyStop = BuyStopLoss(_Symbol,Stop_Loss,openPrice);
      if(buyStop > 0)
         AdjustBelowStopLevel(_Symbol,buyStop);

      double buyProfit = BuyTakeProfit(_Symbol,Take_Profit,openPrice);
      if(buyProfit > 0)
         AdjustAboveStopLevel(_Symbol,buyProfit);

      if(buyStop > 0 || buyProfit > 0)
         Trade.ModifyPosition(glBuyTicket,buyStop,buyProfit);

      glSignal = SIGNAL_NONE;
     }
  }
//+------------------------------------------------------------------+
//|          if the previous trade was a loss                        |
//+------------------------------------------------------------------+
for(i; i>=0; i--)
  {
   if(ord && HistoryDealGetString(ticket,DEAL_SYMBOL) == _Symbol  && HistoryDealGetInteger(ticket,DEAL_MAGIC) == Magic_Number && HistoryDealGetInteger(ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT)
     {
      if(HistoryDealGetDouble(ticket,DEAL_PROFIT) < 0 && cake < Multiply)
        {
         if(co[0]

            &&
            Positions.Buy(Magic_Number) == 0)
           {
            if(glSellTicket > 0)
              {
               Trade.Close(glSellTicket);
              }
            glBuyTicket = Trade.Buy(_Symbol,Multiply);

            if(glBuyTicket > 0)
              {
               double openPrice = PositionOpenPrice(glBuyTicket);

               double buyStop = BuyStopLoss(_Symbol,sl,openPrice);
               if(buyStop > 0)
                  AdjustBelowStopLevel(_Symbol,buyStop);

               double buyProfit = BuyTakeProfit(_Symbol,tp,openPrice);
               if(buyProfit > 0)
                  AdjustAboveStopLevel(_Symbol,buyProfit);

               if(buyStop > 0 || buyProfit > 0)
                  Trade.ModifyPosition(glBuyTicket,buyStop,buyProfit);

               glSignal = SIGNAL_NONE;
              }
           }

        }
     }
  }
//+------------------------------------------------------------------+
//|         Defined signal trail                                     |
//+------------------------------------------------------------------+
if(Use_Trailing_Stop == true && numTickets > 0 && Magic_Number)
  {
   for(int i = 0; i < numTickets; i++)
     {
      Trail.TrailingStop0(tickets[i], Trailing_Stop0, Minimum_Profit0, Step0);

     }
  }

//+------------------------------------------------------------------+
//|   Previous trade was a loss                                      |
//+------------------------------------------------------------------+
if(Use_Trailing_Stop == true && numTickets > 0  && cake >= Multiply && Magic_Number && (HistoryDealGetString(ticket,DEAL_SYMBOL) == _Symbol))
  {
   for(int i = 0; i < numTickets; i++)
     {
      Trail.TrailingStop(tickets[i], Trailing_Stop, Minimum_Profit, Step);

     }
  }
//+------------------------------------------------------------------+


Extract profit down to the last pip
Extract profit down to the last pip
  • www.mql5.com
The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
 
Use a. IF ELSE condition instead of using TWO separate IFs
 
Satyam Shivam #:
Use a. IF ELSE condition instead of using TWO separate IFs

That doesnt work..I have tried it before

 
Satyam Shivam #:
Use a. IF ELSE condition instead of using TWO separate IFs

I tried this...waiting for that scenario  again to happen

 if(HistoryDealGetInteger(ticket,DEAL_MAGIC) == PositionGetInteger(POSITION_MAGIC) && HistoryDealGetString(ticket,DEAL_SYMBOL) == PositionGetString(POSITION_SYMBOL))
                 {