order modify error 1 on gtrailing stop?

 
Anything wrong with this? I keep getting an order modified error.


      int totaltrail = OrdersTotal();
      for(int itrail=totaltrail-1;itrail>=0;itrail--)
      {
         if( OrderSelect(itrail,SELECT_BY_POS) && OrderCloseTime()==0 ) 
         {
            if( OrderType()==OP_BUY ) {
               OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-Point*TrailingStop,NULL,0);
            }
            else if( OrderType()==OP_SELL ) {
               OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]+Point*TrailingStop,NULL,0);
            }
         }
      }
 
SanMiguel:

This error appears when you try to modify an order with the same parameters (stop loss in this case). Try it this way:


     int totaltrail = OrdersTotal();
      for(int itrail=totaltrail-1;itrail>=0;itrail--)
      {
         if( OrderSelect(itrail,SELECT_BY_POS) && OrderCloseTime()==0 ) 
         {
            if(( OrderType()==OP_BUY ) && ((Open[0]-OrderOpenPrice())>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-Point*TrailingStop,NULL,0);
            }
            else if(( OrderType()==OP_SELL ) && ((OrderOpenPrice()-Open[0])>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]+Point*TrailingStop,NULL,0);
            }
         }
      }
 
robofx.org:

This error appears when you try to modify an order with the same parameters (stop loss in this case). Try it this way:


It compiles but in the journal there are no modifications amde to any order. Is Open[0] the right code to use for each tick, should I be using Bid and Ask?


tis fails with erros as well:

int totaltrail = OrdersTotal();
      for(int itrail=totaltrail-1;itrail>=0;itrail--)
      {
         if( OrderSelect(itrail,SELECT_BY_POS) && OrderCloseTime()==0 ) 
         {
            if(( OrderType()==OP_BUY ) && ((Bid-OrderOpenPrice())>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,NULL,0);
            }
            else if(( OrderType()==OP_SELL ) && ((OrderOpenPrice()-Ask)>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,NULL,0);
            }
         }
      }
 
SanMiguel:

It compiles but in the journal there are no modifications amde to any order. Is Open[0] the right code to use for each tick, should I be using Bid and Ask?

Yes, try replacing Open[0] with Bid and Ask.

 
robofx.org:

Yes, try replacing Open[0] with Bid and Ask.

I still get modify error 1 occasionally.

Aha, it's not trailing, it's simply putting the stop 5 away from the price at all times so when price comes back, the stop keeps moving away from it because of orderopenprice()

int totaltrail = OrdersTotal();
      for(int itrail=totaltrail-1;itrail>=0;itrail--)
      {
         if( OrderSelect(itrail,SELECT_BY_POS) && OrderCloseTime()==0 ) 
         {
            if(( OrderType()==OP_BUY ) && ((Bid-OrderOpenPrice())>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,NULL,0);
            }
            else if(( OrderType()==OP_SELL ) && ((OrderOpenPrice()-Ask)>Point*TrailingStop)){
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,NULL,0);
            }
         }
      }
 
SanMiguel:

I still get modify error 1 occasionally:

int totaltrail = OrdersTotal();

for(int itrail=totaltrail-1;itrail>=0;itrail--)

{

if( OrderSelect(itrail,SELECT_BY_POS) && OrderCloseTime()==0 )

{

if(( OrderType()==OP_BUY ) && ((Bid-OrderOpenPrice())>Point*TrailingStop)&&(OrderStopLoss()<Bid-Point*TrailingStop)){

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,NULL,0);

}

else if(( OrderType()==OP_SELL ) && ((OrderOpenPrice()-Ask)>Point*TrailingStop)(OrderStopLoss()>(Ask+Point*TrailingStop)){

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,NULL,0);

}

}

}

 

Still the occasional error. Hmm, do you think this is just price because the next entry doesn't seem to have issues...

2009.06.26 18:39:19	2009.06.26 07:12  LowVolumeBreakout GBPUSD,H1: modify #9 buy 1.00 GBPUSD at 1.6451 sl: 1.6458 tp: 0.0000 ok
2009.06.26 18:39:19	2009.06.26 07:12  LowVolumeBreakout GBPUSD,H1: OrderModify error 1
2009.06.26 18:39:19	2009.06.26 07:11  LowVolumeBreakout GBPUSD,H1: modify #9 buy 1.00 GBPUSD at 1.6451 sl: 1.6457 tp: 0.0000 ok
2009.06.26 18:39:19	2009.06.26 07:11  LowVolumeBreakout GBPUSD,H1: modify #9 buy 1.00 GBPUSD at 1.6451 sl: 1.6454 tp: 0.0000 ok
2009.06.26 18:39:19	2009.06.26 07:11  LowVolumeBreakout GBPUSD,H1: modify #9 buy 1.00 GBPUSD at 1.6451 sl: 1.6452 tp: 0.0000 ok
2009.06.26 18:39:19	2009.06.26 07:10  LowVolumeBreakout GBPUSD,H1: delete #10 sell stop 1.00 GBPUSD at 1.6357 sl: 1.6387 tp: 1.6257 ok
2009.06.26 18:39:19	2009.06.26 07:10  Tester: order #9, buy 1.00 GBPUSD is opened at 1.6451
2009.06.26 18:39:19	2009.06.26 05:00  LowVolumeBreakout GBPUSD,H1: open #10 sell stop 1.00 GBPUSD at 1.6357 sl: 1.6387 tp: 1.6257 ok
2009.06.26 18:39:19	2009.06.26 05:00  LowVolumeBreakout GBPUSD,H1: open #9 buy stop 1.00 GBPUSD at 1.6451 sl: 1.6421 tp: 1.6551 ok
 
SanMiguel:

Still the occasional error. Hmm, do you think this is just price because the next entry doesn't seem to have issues...

Hmm.. strange but can be caused of price. For example if Bid-Point*TrailingStop becomes equal to OrderStopLoss() the new stop loss will be the same as previous and this error would appear.

Not a big deal anyway.