help me trailing stop of buy sell stop

 
void PlaceOrder(int iSignal){

   int iTicket;
   double op1=Ask+BuyStop*Point;
   double op2=Bid-SellStop*Point;
   
   
   
   if(iSignal == 1)
   {
      iTicket=OrderSend(Symbol(),OP_BUYSTOP,dLots,  op1,3,op1-iStopLoss*Point,op1+iTakeProfit*Point,"My First EA",iMagicNumber,0,Green);
      if(iTicket>0){
         if(OrderSelect(iTicket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
      }else{
         Print("Error opening BUY order : ",GetLastError());
      }
   }
   
   if(iSignal == 2)
   {
      iTicket=OrderSend(Symbol(),OP_SELLSTOP,dLots,op2,3,op2+iStopLoss*Point,op2-iTakeProfit*Point,"My First EA",iMagicNumber,0,Red);
      if(iTicket>0){
         if(OrderSelect(iTicket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
      }else{
         Print("Error opening SELL order : ",GetLastError());
      }
   }   
   return(0);
   
}

void TrailingStop(int iTotal){

   int iCount;
   double op1=Ask+BuyStop*Point;
   double op2=Bid-SellStop*Point;
   
   
   if(iTrailingStop < 1)return(-1); // error
   
   for(iCount=0;iCount<iTotal;iCount++){

      OrderSelect(iCount, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber() == iMagicNumber)
         switch(OrderType()){
            case OP_BUYSTOP:
               if(Bid-OrderOpenPrice()>Point*iTrailingStop){
                  if(OrderStopLoss()<Bid-Point*iTrailingStop){
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*iTrailingStop,OrderTakeProfit(),0,Green);
                  }
               }
               break;
            case OP_SELLSTOP:
               if((OrderOpenPrice()-Ask)>(Point*iTrailingStop)){
                  if((OrderStopLoss()>(Ask+Point*iTrailingStop)) || (OrderStopLoss()==0)){
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*iTrailingStop,OrderTakeProfit(),0,Red);
                  }
               }
               break;
         }
      }
   
      return(0);
what wrong with trailing stop
 
phipho:
what wrong with trailing stop

Why do this,  your function is type void so it does not return a value . . .

if(iTrailingStop < 1)return(-1); // error

 

Why check this here ?  why not check before you call the function . . .

if(iTrailingStop > 0) TrailingStop( OrdersTotal() );

 

How can this be possible for a BUYSTOP ?

if( Bid - OrderOpenPrice() > Point * iTrailingStop )

 Have you ever read and understood this ?  : Requirements and Limitations in Making Trades

 

Your  pending Stop trades has become Buy or Sell

the moment

           case OP_BUYSTOP: 

               if Ask-OrderOpenPrice()>= 0   it will become a Buy trade

            case OP_SELLSTOP:

               if OrderOpenPrice() - Bid  >= 0   it will become a Sell trade

 
i'm try to repair but i hard for me. I can't do it hiccc
 
phipho:
i'm try to repair but i hard for me. I can't do it hiccc


price this moment 1.50000

you place a new buystop  orderopenprice  =Ask+BuyStop*Point;    SL=orderopenprice-iStopLoss*Point     TP=orderopenprice+iTakeProfit*Point

if(Bid-OrderOpenPrice()>Point*iTrailingStop)

 means price above orderopenprice

 if that happens you haven't a buystop trade it has become a buy trade !!!!

 
deVries:


price this moment 1.50000

you place a new buystop  orderopenprice  =Ask+BuyStop*Point;    SL=orderopenprice-iStopLoss*Point     TP=orderopenprice+iTakeProfit*Point

 means price above orderopenprice

 if that happens you haven't a buystop trade it has become a buy trade !!!!

 

 

So now I have to do?
 
phipho:
So now I have to do?

case OP_BUYSTOP:

change it to   ???

case OP_BUY:

or is that also hard to understand 

 
i change but it not work.
void TrailingStop(int iTotal){

   int iCount;
   
   if(iTrailingStop < 1)return(-1); // error
   
   for(iCount=0;iCount<iTotal;iCount++){

      OrderSelect(iCount, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber() == iMagicNumber)
         switch(OrderType()){
            case OP_BUY:
               if(Bid-OrderOpenPrice()>Point*iTrailingStop){
                  if(OrderStopLoss()<Bid-Point*iTrailingStop){
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*iTrailingStop,OrderTakeProfit(),0,Green);
                  }
               }
               break;
            case OP_SELL:
               if((OrderOpenPrice()-Ask)>(Point*iTrailingStop)){
                  if((OrderStopLoss()>(Ask+Point*iTrailingStop)) || (OrderStopLoss()==0)){
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*iTrailingStop,OrderTakeProfit(),0,Red);
                  }
               }
               break;
         }
      }
   
      return(0);
 
phipho:
i change but it not work.
How do you see it does not work ?
 
angevoyageur:
How do you see it does not work ?

i backtest. I have buystop and when buystop become buy, When i have proit so take profit and stoploss it work  but trailingstop not work.
 
phipho:

i backtest. I have buystop and when buystop become buy, When i have proit so take profit and stoploss it work  but trailingstop not work.
Ok, what are the values of your stoploss, takeprofit and iTrailingStop ?
Reason: