Трелинг. Где то есть ошибка, а вот где !?

 

Написал функцию трелинга, для ордеров buy модификацию делает, а вот для sell нет. Не могу разобраться где ошибка !?

void TSHL()
   {
   int total = OrdersTotal();
   int cnt;
   if(total > 0)
    {
     for(cnt=0;cnt<total;cnt++)
      {
       bool cntOrd = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
//-----------------------------------------------------------------------------------------------------       
       if(OrderType() == OP_BUY)
        {
         int L_Bar = iLowest(NULL, 0, MODE_LOW, TS_Bars, 0);
         if(iClose(NULL, 0, L_Bar)>iOpen(NULL, 0, L_Bar))
          {
           double L_telo_1 = iClose(NULL, 0, L_Bar) - iOpen(NULL, 0, L_Bar);
           double L_ten_1 = iOpen(NULL, 0, L_Bar) - iLow(NULL, 0, L_Bar);
          }
           
         if(iClose(NULL, 0, L_Bar)<iOpen(NULL, 0, L_Bar))
           {
            double L_telo_2 = iOpen(NULL, 0, L_Bar) - iClose(NULL, 0, L_Bar);
            double L_ten_2 = iClose(NULL, 0, L_Bar) - iLow(NULL, 0, L_Bar);
           }
         if(L_ten_1 > L_telo_1 || L_ten_2 > L_telo_2)
          {
           if(iFractals(NULL, 0, MODE_LOWER, L_Bar)!=0)
           {
            double L_price = iLow(NULL, 0, L_Bar);          
            if(OrderStopLoss()<L_price)
             {
              bool rb = OrderModify(OrderTicket(), OrderOpenPrice(), L_price, OrderTakeProfit(), 0, Green);
             }
           }
          }
        }
//---------------------------------------------------------------------------------------------------------------        
       if(OrderType() == OP_SELL)
        {
         int H_Bar = iHighest(NULL, 0, MODE_HIGH, TS_Bars, 0);
         if(iClose(NULL, 0, H_Bar)>iOpen(NULL, 0, H_Bar))
          {
           double H_telo_1 = (iClose(NULL, 0, H_Bar) - iOpen(NULL, 0, H_Bar));
           double H_ten_1 = (iHigh(NULL, 0, H_Bar) - iClose(NULL, 0, H_Bar));
          }
           
         if(iClose(NULL, 0, H_Bar)<iOpen(NULL, 0, H_Bar))
           {
            double H_telo_2 = (iOpen(NULL, 0, H_Bar) - iClose(NULL, 0, H_Bar));
            double H_ten_2 = (iHigh(NULL, 0, H_Bar) - iOpen(NULL, 0, H_Bar));
           }
         if(H_ten_1 > H_telo_1 || H_ten_2 > H_telo_2)
          {
           if(iFractals(NULL, 0, MODE_HIGH, H_Bar)!=0)
            {
             double H_price = iHigh(NULL, 0, H_Bar);          
             if(OrderStopLoss()>H_price)
              {
               bool rs = OrderModify(OrderTicket(), OrderOpenPrice(), H_price, OrderTakeProfit(), 0, Green);
              }
            }
          }
        }
       }
      }
     }
 

попробуй там где:

if(OrderStopLoss()>H_price)

поставить

if(OrderStopLoss()>H_price || OrderStopLoss()==0)