Long trailingstop works really fine, but why short trailingstop doens't work??>

 

OMG,, this is driving me crazy..

Long positioin works fine but why short position doesn't !!!

I checked Symbol, MagicNo, Everything...

Now,, just gently requesting the help from your fresh eyes,,,

My eyes are no good any more..

Any comment and any suggestion will help,

Thanks.

    //================Averaging*/
       if(OrderType() == OP_SELL) {
    open_sell++;
//    TotalSellProfit=TotalSellProfit+OrderProfit()+OrderSwap()+OrderCommission();
    if(FirstSellTime==0 || FirstSellTime>OrderOpenTime()) {
     FirstSellTime=OrderOpenTime();
     FirstSellPrice=OrderOpenPrice();
     FirstSellLot=OrderLots();
     FirstSellStopLoss=OrderStopLoss();
     FirstSellTakeProfit=OrderTakeProfit();
    }
    if(LastSellTime<OrderOpenTime()) {
     LastSellTime=OrderOpenTime();
     LastSellPrice=OrderOpenPrice();
     LastSellLot=OrderLots();
     LastSellStopLoss=OrderStopLoss();
     LastSellTakeProfit=OrderTakeProfit();
    }
    if(OrderStopLoss()==0 || OrderTakeProfit()==0) {
     if(StoplossUse) tmpStoploss=OrderOpenPrice()+Stoploss*PointDigit; else tmpStoploss=0;
     if(TakeprofitUse) tmpTakeprofit=OrderOpenPrice()-Takeprofit*PointDigit; else tmpTakeprofit=0;
     if(tmpStoploss>0 || tmpTakeprofit>0) OrderModify(OrderTicket(),OrderOpenPrice(),tmpStoploss,tmpTakeprofit,0,DarkOrange);
    }
    if(TrailingstopUse == true ){     
   
    if ( OrdersTotal() == 1 ) {
     if(OrderOpenPrice() - Ask > TrailingSinglestop*PointDigit) {
     if(OrderStopLoss() > Ask + (TrailingSinglestop+TrailingSinglestep-1)*PointDigit) {
      OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (TrailingSinglestop) * PointDigit, OrderTakeProfit(), 0, DarkOrange);
     }
     }
    }
    

    if( OrdersTotal() > 1 ) {
     if(AvgPrice - Ask > Trailingstop*PointDigit) {
     if(OrderStopLoss() > Ask + (Trailingstop+Trailingstep-1)*PointDigit) {
      OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (Trailingstep) * PointDigit, OrderTakeProfit(), 0, DarkOrange);
     }
     }
    }
    }
   
  } 
   if(OrderType()==OP_BUY) {
    open_buy++;
    if(FirstBuyTime==0 || FirstBuyTime>OrderOpenTime()) {
     FirstBuyTime=OrderOpenTime();
     FirstBuyPrice=OrderOpenPrice();
     FirstBuyLot=OrderLots();
     FirstBuyStopLoss=OrderStopLoss();
     FirstBuyTakeProfit=OrderTakeProfit();
    }
    if(LastBuyTime<OrderOpenTime()) {
     LastBuyTime=OrderOpenTime();
     LastBuyPrice=OrderOpenPrice();
     LastBuyLot=OrderLots();
     LastBuyStopLoss=OrderStopLoss();
     LastBuyTakeProfit=OrderTakeProfit();
    } 
    if(OrderStopLoss()==0 || OrderTakeProfit()==0) {
     if(StoplossUse) tmpStoploss=OrderOpenPrice()-Stoploss*PointDigit; else tmpStoploss=0;
     if(TakeprofitUse) tmpTakeprofit=OrderOpenPrice()+Takeprofit*PointDigit; else tmpTakeprofit=0;
     if(tmpStoploss>0 || tmpTakeprofit>0) OrderModify(OrderTicket(),OrderOpenPrice(),tmpStoploss,tmpTakeprofit,0,DarkOrange);
    }
    if(TrailingstopUse == true && TrailingSinglestop > 0){ 
    
    if ( OrdersTotal() == 1 ) {
      if(Bid-OrderOpenPrice()>TrailingSinglestop*PointDigit) {
      if(OrderStopLoss() < Bid - (TrailingSinglestop+TrailingSinglestep-1)*PointDigit) {
       OrderModify(OrderTicket(),OrderOpenPrice(),Bid - (TrailingSinglestop)*PointDigit, OrderTakeProfit(), 0, MediumSeaGreen);
      }
      }
      }
    if( OrdersTotal() > 1 ) {
     if(Bid-AvgPrice>Trailingstep*PointDigit) {
     if(OrderStopLoss() < Bid - (Trailingstop+Trailingstep-1)*PointDigit) {
      OrderModify(OrderTicket(),OrderOpenPrice(),Bid - (Trailingstop)*PointDigit, OrderTakeProfit(), 0, MediumSeaGreen);
         //   SuperBuyStopLoss = Bid - (Trailingstop)*PointDigit;
     }
     }
     }
    }

   }

  }
//  }
 
kyle1681:

Any comment and any suggestion will help,

Thanks.

Your indenting is horrible . . . IMO, maybe you love it . .

     }
     }
     }
    }

   }

  }

Check return values from your OrderModify, if it fails Print a message telling you the ticket number, the error number and any other helpful info . . .

I don't see an OrderSelect . . . I assume you check that it works ? if not you should.

 
Because of......
    //================Averaging*/
       if(OrderType() == OP_SELL) {       //  <<===  HERE FIRST BRACKET OPEN  OP_SELL
    open_sell++;
//    TotalSellProfit=TotalSellProfit+OrderProfit()+OrderSwap()+OrderCommission();
    if(FirstSellTime==0 || FirstSellTime>OrderOpenTime()) {   // << OKE 1
     FirstSellTime=OrderOpenTime();
     FirstSellPrice=OrderOpenPrice();
     FirstSellLot=OrderLots();
     FirstSellStopLoss=OrderStopLoss();
     FirstSellTakeProfit=OrderTakeProfit();
    }                                                         // CLOSE 1  
    if(LastSellTime<OrderOpenTime()) {                        //  << OKE 2
     LastSellTime=OrderOpenTime();
     LastSellPrice=OrderOpenPrice();
     LastSellLot=OrderLots();
     LastSellStopLoss=OrderStopLoss();
     LastSellTakeProfit=OrderTakeProfit();
    }                                                         // CLOSE 2
    if(OrderStopLoss()==0 || OrderTakeProfit()==0) {          //  <<   3
     if(StoplossUse) tmpStoploss=OrderOpenPrice()+Stoploss*PointDigit; else tmpStoploss=0;
     if(TakeprofitUse) tmpTakeprofit=OrderOpenPrice()-Takeprofit*PointDigit; else tmpTakeprofit=0;
     if(tmpStoploss>0 || tmpTakeprofit>0) OrderModify(OrderTicket(),OrderOpenPrice(),tmpStoploss,tmpTakeprofit,0,DarkOrange);
    } // CLose 3  If one of those is 0 it will modify every time again
      // if it is changed one Time

/*    // WHY  NOT.......  
    if(OrderStopLoss()==0 && OrderTakeProfit()==0) {            // && instead of ||
     if(StoplossUse) tmpStoploss=OrderOpenPrice()+Stoploss*PointDigit; else tmpStoploss=0;
     if(TakeprofitUse) tmpTakeprofit=OrderOpenPrice()-Takeprofit*PointDigit; else tmpTakeprofit=0;
     if(tmpStoploss>0 || tmpTakeprofit>0) OrderModify(OrderTicket(),OrderOpenPrice(),tmpStoploss,tmpTakeprofit,0,DarkOrange);
    }      
*/      
       
    if(TrailingstopUse == true ){     // OKE 4.
   
    if ( OrdersTotal() == 1 ) {       // 4.1
     if(OrderOpenPrice() - Ask > TrailingSinglestop*PointDigit) {       // 4.2
     if(OrderStopLoss() > Ask + (TrailingSinglestop+TrailingSinglestep-1)*PointDigit) {    // 4.3   WHY TrailingSinglestep-1
                                                                                            // if TrailingSinglestep = 1 it goes wrong modify same SL          
      OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (TrailingSinglestop) * PointDigit, OrderTakeProfit(), 0, DarkOrange);
     }   // end 4.1
     }   // end 4.2
    }    // end 4.3
    

    if( OrdersTotal() > 1 ) {    // 4.4  OrdersTotal() can be also > 1 if other Symbol is trading
     if(AvgPrice - Ask > Trailingstop*PointDigit) {  // 4.5 What is AvgPrice ??  
                                                     //       With only sells or buys and sells
     if(OrderStopLoss() > Ask + (Trailingstop+Trailingstep-1)*PointDigit) {  //4.6   again TrailingSinglestep-1
      OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (Trailingstep) * PointDigit, OrderTakeProfit(), 0, DarkOrange);      // << YOUR ERROR TRAILINGSTEP
     } //end 4.4
     } // end 4.5
    } //end 4.6
    } // end 4.
   
  } // end OP_SELL 
Reason: