"Invalid S/L or T/P" issue

 

Hi to all,

I'm studying EA building for some months and since the last week I've my EA running in a Live account.

My EA close positions based on trailing stop (Trailing start at 2.5 pips of profit, 1.0 pips of step)

In strategy tester all is OK but now in a live environment I see that sometimes my order modify commands get rejected (most of times modification is successfull).

My opinion is that my Trailing Step is very tight so, it is possible that in the time that passes from my "set S/L" command and the real execution of that command price changes and then my SL become higher than Ask (example of Buy position). 


These are two log error messages that I've received during last session:

2018.06.05 23:07:26.044 : modification of order #3057222 sell 0.06 GBPUSD at 1.33968 sl: 1.34199 tp: 1.33809 -> sl: 1.33943 tp: 0.00000 failed [Invalid S/L or T/P]
2018.06.05 23:07:25.794 : modify order #3057222 sell 0.06 GBPUSD at 1.33968 sl: 1.34199 tp: 1.33809 -> sl: 1.33943 tp: 0.00000
2018.06.05 23:07:23.904 : modification of order #3057222 sell 0.06 GBPUSD at 1.33968 sl: 1.34199 tp: 1.33809 -> sl: 1.33943 tp: 0.00000 failed [Invalid S/L or T/P]
2018.06.05 23:07:23.654 : modify order #3057222 sell 0.06 GBPUSD at 1.33968 sl: 1.34199 tp: 1.33809 -> sl: 1.33943 tp: 0.00000


I attach the Trailing function of my EA.

void Trailing()
{
         int total=OrdersTotal();
         for (int z=0;z<total;z++)
            { 
               if( OrderSelect(z, SELECT_BY_POS) )
               {   
                  int mode=OrderType();    
                  if ( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) 
                     if( mode==OP_BUY )              
                        if( Bid - OrderOpenPrice() > Point * TrailingStart * 10) 
                           if(OrderStopLoss() < Bid - Point * TrailingStep * 10)
                              if( OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStep , 0, 0, MediumSeaGreen) ) continue;
                     if( mode==OP_SELL )
                        if( OrderOpenPrice() - Ask > (Point * TrailingStart * 10) )
                           if((OrderStopLoss() > (Ask + Point * TrailingStep * 10) ) )
                              if( OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStep , 0, 0, DarkOrange) ) continue;
               }
            }
}


What do you think about?

Thanks to all for knowledge! :)

Fabio

 
kava93:

Hi to all,

I'm studying EA building for some months and since the last week I've my EA running in a Live account.

My EA close positions based on trailing stop (Trailing start at 2.5 pips of profit, 1.0 pips of step)

In strategy tester all is OK but now in a live environment I see that sometimes my order modify commands get rejected (most of times modification is successfull).

My opinion is that my Trailing Step is very tight so, it is possible that in the time that passes from my "set S/L" command and the real execution of that command price changes and then my SL become higher than Ask (example of Buy position). 


These are two log error messages that I've received during last session:


I attach the Trailing function of my EA.


What do you think about?

Thanks to all for knowledge! :)

Fabio


Your new stop loss level (1.33943) was probably too close to the current price (1.33968), difference is 2.5 pips only which is very small. In normal trading hours it may work (even if it is very tight) but during night hours many brokers widen spreads and other trading parameters and thus your operation could not meet required conditions.

https://book.mql4.com/appendix/limits

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Tables below show calculation values that limit the conduction of trades when opening, closing, placing, deleting or modifying orders. To get the minimum distance to StopLevel and freezing distance FreezeLevel the MarketInfo() function should be called. Requirements. Correct prices used when performing trade operations. Order Type Open Price...
 
Bartlomiej Gorski:


Your new stop loss level (1.33943) was probably too close to the current price (1.33968), difference is 2.5 pips only which is very small. In normal trading hours it may work (even if it is very tight) but during night hours many brokers widen spreads and other trading parameters and thus your operation could not meet required conditions.

https://book.mql4.com/appendix/limits

Thanks a lot for your reply!!

I will try to use MODE_STOPLEVEL when I set my SL.

Do you think that it is better to close positions with OrderClose command instead of making trailing stop in night hours?


Thanks again!!