Why is sell trailing stop not working !!!!!!!!!!!

 
void TrailingBuy(){       for(cnt=OrdersTotal()-1;cnt>=0;cnt--){    if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))    if(OrderSymbol()==Symbol())    if(OrderMagicNumber()==Magic)    if(OrderType()==OP_BUY)    if(Bid-OrderOpenPrice()>TrailingStop*Point)    if(OrderStopLoss()<Bid-TrailingStep*Point)    bool zs = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,clrAliceBlue);  


THAT Function WORK SUCCESSFULY but the SELL TRAILING FUNCTION IS NOT WORKING in the tester !!!!!


void TrailingSell(){

  

   for(cnt=OrdersTotal()-1;cnt>=0;cnt--){

   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))

   if(OrderSymbol()==Symbol())

   if(OrderMagicNumber()==Magic)

   if(OrderType()==OP_SELL)

   if(OrderOpenPrice()-Ask>TrailingStop*Point)

   if(OrderStopLoss()>Ask+TrailingStep*Point)

   bool zs = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,clrRed);


CAN ANY ONE HELP ME WHY IT IS NOT WORKING !! PLEASE I AM SO UPSET

 

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
  1. You correctly wrote:
    if(Bid-OrderOpenPrice() > TrailingStop*Point)      // Break even
    if(OrderStopLoss()      < Bid-TrailingStep*Point)  // and higher.
    Inverting for selling gives:
    if(OrderOpenPrice()-Ask > TrailingStop*Point)
    if(OrderStopLoss()      < Ask+TrailingStep*Point) 
    But you wrote
    if(OrderOpenPrice()-Ask > TrailingStop*Point)
    if(OrderStopLoss()      > Ask+TrailingStep*Point)

  2. Isn't better to write it as:

    double newSL= Bid-TrailingStep*Point;
    if(newSL > MathMax( OrderStopLoss(), OrderOpenPrice() )) // BE and higher.
    bool zs = OrderModify(OrderTicket(),OrderOpenPrice(),newSL,OrderTakeProfit(),0,clrAliceBlue);   
  3. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

 
William Roeder #:
  1. You correctly wrote:
    Inverting for selling gives:
    But you wrote

  2. Isn't better to write it as:

  3. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

Thanks a lot it worked finally .. sorry i did not know about that code button 

 
Sergey Golubev #:

When you post code please use the CODE button (Alt-S)!

ok i will sorry

 
William Roeder #:
  1. You correctly wrote:
    Inverting for selling gives:
    But you wrote

  2. Isn't better to write it as:

  3. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

void TrailingSell()
  {
   for(cnt=OrdersTotal()-1; cnt>=0; cnt--)
     {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
            if(OrderMagicNumber()==Magic)
               if(OrderType()==OP_SELL)
                  if(OrderOpenPrice()-Ask>TrailingStop*Point)
                     if(OrderStopLoss()<Ask+TrailingStep*Point)
                         bool zs = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStep*Point,OrderTakeProfit(),0,clrAliceBlue); 
                       
     }
  }

I have modified the code but the trailing do not move more than break even !

please look at photo attached if you know why it do not move more i will be Glad , Thanks Again

<image deleted>
 
Ahmed Gouda #:

I have modified the code but the trailing do not move more than break even !

please look at photo attached if you know why it do not move more i will be Glad , Thanks Again

<image deleted>

I have deleted your image as it is not relevant (only showed pending orders).

                  if(OrderOpenPrice()-Ask>TrailingStop*Point)
                     if(OrderStopLoss()<Ask+TrailingStep*Point)

I don't understand your logic.

Surely it should be

                  if(OrderOpenPrice()-Ask>=TrailingStop*Point)
                     if(OrderStopLoss()>Ask+TrailingStep*Point)
Reason: