Trailing Stop - OrderTakeProfit()

 
In the OrderModify functoin for order type OP_BUY, I can increase the OrderTakeProfit() value, but If I try to lower the OrderTakeProfit() value, I get Message "unknown ticket for OrderModify function", and the reverse is true for the OrderModify function for order type OP_SELL.

The following gives the error message above.

tpAdjust= 0.9995;

if(OrderType()==OP_BUY)
if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit()*[b}tpAdjust[/b],0,Green); }
}

If tpAdjust=1.0005; It works just fine.

My Question is; In the OrderModify function, can the OrderTakeProfit() value be lowered in OP_BUY type orders and increased in OP)_SELL type orders?

Wackena
 
Do You select order previously by the OrderSelect function?
 
Do You select order previously by the OrderSelect function?



Yes. Order select precedes this part of the code. As stated, the OrderModify works OK if I increase tp on OP_BUY.

Wackena
 
Cannot reproduce
17:47:28 TestModify USDJPY,H1: modify #3912748 buy 0.10 USDJPY at 116.4900 sl: 116.5900 tp: 117.1000 ok
17:47:45 TestModify USDJPY,H1: modify #3912748 buy 0.10 USDJPY at 116.4900 sl: 116.6000 tp: 117.0400 ok
17:47:59 TestModify USDJPY,H1: modify #3912748 buy 0.10 USDJPY at 116.4900 sl: 116.6000 tp: 116.9800 ok
 
Slawa, here is the code in question. When I run this code with only OrderTakeProfit(), the Trailing stop functions works OK. But the code below returns the Message unknown ticket# or invalid order for OrderModify function.
//=============== TRAILING STOP REGULAR ORDERS 
   int total=0; 
   int cnt=0;
   total = OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if((OrderType() <= OP_SELL) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() ==MagicNumber))
         {
         if(OrderType() == OP_BUY)
            {
            if(UseTrailingStop)
               {
               if((Bid-OrderOpenPrice()) > (Point*TrailingStop))
                  {
                  if((OrderStopLoss()) < (Bid-Point*TrailingStop))
                     {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit()*0.9995,0,GreenYellow);
                     return(0);
                     }
                  } 
               }                    
             }

            if(OrderType() == OP_SELL)
               {
               if(UseTrailingStop)
                  {
                  if(OrderOpenPrice()-Ask>Point*TrailingStop)
                     {
                     if(OrderStopLoss()>Ask+Point*TrailingStop)
                        {
                        OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit()*1.0005,0,Red);
                        return(0);              
                        }
                     }     
                  }
                }
             }
          }


Thank you for your help.

Wackena

 
Wackena, next time please use 'code' tags for sources. (i've inserted they into your post)

I'll check your code tomorrow.
 
Wackena, next time please use 'code' tags for sources. (i've inserted they into your post)

I'll check your code tomorrow.


Slawa,

Have you had a chance to test this code?

Wackena
 
This code works correctly. I cannot reproduce problem
 
This code works correctly. I cannot reproduce problem


Slawa,
Thank you very much. I don't know why, but if I test code on FXDD Demo, it doesn't work. But it works just fine on IBFX Demo.
Wackena
Reason: