[invalid stops] during modification

 

Hello, I find an Error during  backtesting  as shown in this pic

While: 

void ModifyBuy (string Symboll , double StopLoss, double TakeProfit )
            {
               for(int posIndex=PositionsTotal()-1;  posIndex>=0;   posIndex--   )
                                                                                   {
                                                                                         ulong ticket = PositionGetTicket(posIndex);
                                                                                     if( Symboll == PositionGetSymbol(posIndex))
                                                                                     if( PositionSelectByTicket(ticket)  )
                                                                                     if( PositionGetInteger(POSITION_MAGIC)==MagicNumber)
                                                                                     if( PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
                                                                                     
                                                                                     trade.PositionModify(ticket,StopLoss,TakeProfit);
                                                                                   }
                     return;
              }

and ModifySell has a similar code

Note: I tried to enter Zero's instead of StopLoss and TakeProfit but the same result

So, no problem in these values.

 
Amgad Samir Nassief Abdelmalek:

Hello, I find an Error during  backtesting  as shown in this pic

While: 

and ModifySell has a similar code

Note: I tried to enter Zero's instead of StopLoss and TakeProfit but the same result

So, no problem in these values.

Can't say it for sure (code & screenshot don't show the full neded info), but look in your journal 1-2 lines higher than your screenshot shows and compare the actual price with the new SL you want to set.

You should add a check in your sourcecode, that the new SL isn't higher than the actual price in a buy-position, and for sells vice-versa.

 
Thomas S. #:

Can't say it for sure (code & screenshot don't show the full neded info), but look in your journal 1-2 lines higher than your screenshot shows and compare the actual price with the new SL you want to set.

You should add a check in your sourcecode, that the new SL isn't higher than the actual price in a buy-position, and for sells vice-versa.

Sir, I put 0 SL and tried to set 100Pips

both reaches the same results 

The Second point is: why this problem only with modifications?

I don't see this problem with buy or sell orders

 
Amgad Samir Nassief Abdelmalek #:

Sir, I put 0 SL and tried to set 100Pips

both reaches the same results 

The Second point is: why this problem only with modifications?

I don't see this problem with buy or sell orders

Don't assume and don't ask us to assume. You show a "sell" modify error and a "buy" modify code. Show the corresponding code and log.

If you tried with a SL of 0, show the log too. Add error processing in your code.

Anyway, this code is not correct :

ulong ticket = PositionGetTicket(posIndex);
if( Symboll == PositionGetSymbol(posIndex))
if( PositionSelectByTicket(ticket)  )

You need to either use PositionGetTicket() or PositionGetSymbol() (on an netting account only) or PositionSelectByTicket() not the true, only ONE. If your account is an hedging account PositionGetTicket(index) is correct and after that to get the position symbol use PositionGetString(POSITION_SYMBOL).

 
Alain Verleyen #:

Don't assume and don't ask us to assume. You show a "sell" modify error and a "buy" modify code. Show the corresponding code and log.

If you tried with a SL of 0, show the log too. Add error processing in your code.

Anyway, this code is not correct :

You need to either use PositionGetTicket() or PositionGetSymbol() (on an netting account only) or PositionSelectByTicket() not the true, only ONE. If your account is an hedging account PositionGetTicket(index) is correct and after that to get the position symbol use PositionGetString(POSITION_SYMBOL).

Sir, my account is neither Hedging  not netting but I need to use  PositionGetSymbol()  because I design Multi-symbol 

and I send a photo for zero SL


and this photo for my 0 S/L and also I make 0 T/P

 
Amgad Samir Nassief Abdelmalek #:

Sir, my account is neither Hedging  not netting but I need to use  PositionGetSymbol()  because I design Multi-symbol 

You don't listen. An MT5 is always either hedging or netting, there is not a third option. Did you fix your code ?

and I send a photo for zero SL


and this photo for my 0 S/L and also I make 0 T/P

That's weird for sure. What broker are you using ? is this a demo or a live account ?

Please post the full logs from the Strategy Tester as a file (not a screenshot).

 
Alain Verleyen #:
You don't listen. An MT5 is always either hedging or netting, there is not a third option. Did you fix your code ?

That's weird for sure. What broker are you using ? is this a demo or a live account ?

Please post the full logs from the Strategy Tester as a file (not a screenshot).

1- my broker is IC Markets 

2- I have real account but I test this strategy on demo (turning EA on) with no problem

3- I tried to send the Strategy taster and an HTML or Excel file but it is invalid here 

So I send you a copy on txt file


Files:
 
Amgad Samir Nassief Abdelmalek #:

1- my broker is IC Markets 

2- I have real account but I test this strategy on demo (turning EA on) with no problem

3- I tried to send the Strategy taster and an HTML or Excel file but it is invalid here 

You need to zip it.

So I send you a copy on txt file

You are trying PositionModify() with the same SL/TP which is already set.

2022.01.19 04:37:52.332 Trade 2022.01.10 00:01:01 market buy 0.01 GBPUSD sl: 1.34741 tp: 1.35956 (1.35917 / 1.35927)
2022.01.19 04:37:52.332 Trades 2022.01.10 00:01:01 deal #10 buy 0.01 GBPUSD at 1.35927 done (based on order #10)
2022.01.19 04:37:52.332 Trade 2022.01.10 00:01:01 deal performed [#10 buy 0.01 GBPUSD at 1.35927]
2022.01.19 04:37:52.332 Trade 2022.01.10 00:01:01 order performed buy 0.01 at 1.35927 [#10 buy 0.01 GBPUSD at 1.35927]
2022.01.19 04:37:52.332 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:01:01 CTrade::OrderSend: market buy 0.01 GBPUSD sl: 1.34741 tp: 1.35956 [done at 1.35927]
2022.01.19 04:37:52.332 Trades 2022.01.10 00:01:01 failed modify #10 buy 0.01 GBPUSD sl: 1.34741, tp: 1.35956 -> sl: 1.34741, tp: 1.35956 [Invalid stops]
2022.01.19 04:37:52.332 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:01:01 CTrade::OrderSend: modify position #10 GBPUSD (sl: 1.34741, tp: 1.35956) [invalid stops]
...
2022.01.19 04:37:52.333 Trades 2022.01.10 00:05:41 failed modify #10 buy 0.01 GBPUSD sl: 1.34741, tp: 1.35956 -> sl: 1.34741, tp: 1.35956 [Invalid stops]
2022.01.19 04:37:52.333 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:05:41 CTrade::OrderSend: modify position #10 GBPUSD (sl: 1.34741, tp: 1.35956) [invalid stops]
2022.01.19 04:37:52.333 Trade 2022.01.10 00:05:43 position modified [#10 buy 0.01 GBPUSD 1.35927 sl: 1.35012 tp: 1.35953]
2022.01.19 04:37:52.333 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:05:43 CTrade::OrderSend: modify position #10 GBPUSD (sl: 1.35012, tp: 1.35953) [done]
2022.01.19 04:37:52.333 Trade 2022.01.10 00:05:51 position modified [#10 buy 0.01 GBPUSD 1.35927 sl: 1.34994 tp: 1.35953]
2022.01.19 04:37:52.333 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:05:51 CTrade::OrderSend: modify position #10 GBPUSD (sl: 1.34994, tp: 1.35953) [done]
2022.01.19 04:37:52.333 Trades 2022.01.10 00:05:52 failed modify #10 buy 0.01 GBPUSD sl: 1.34994, tp: 1.35953 -> sl: 1.34994, tp: 1.35953 [Invalid stops]
2022.01.19 04:37:52.333 Flecha Scalper EA (EURUSD,M15) 2022.01.10 00:05:52 CTrade::OrderSend: modify position #10 GBPUSD (sl: 1.34994, tp: 1.35953) [invalid stops]
2022.01.19 04:37:52.333 Trades 2022.01.10 00:06:01 failed modify #10 buy 0.01 GBPUSD sl: 1.34994, tp: 1.35953 -> sl: 1.34994, tp: 1.35953 [Invalid stops]
 
Alain Verleyen #:
You need to zip it.

You are trying PositionModify() with the same SL/TP which is already set.

Mr. Alain you're really so Clever, I really didn't note this mistake before

I'll try to find a method to modify at changing values of TP and SL, I really don't know how but I'll try again


anyway, I'm so glad for your help and It's my pleasure to meet you

and Thank you again 🌹🌹🌹

 
You can query the current values and compare them to your "new" values to see if you need to update them.

PositionGetDouble(POSITION_SL)


 
Dominik Christian Egert #:
You can query the current values and compare them to your "new" values to see if you need to update them.

PositionGetDouble(POSITION_SL)


I tried 

if ( PositionGetDouble(POSITION_SL) != sl )
trade.PositionModify (ticket, sl, PositionGetDouble(POSITION_TP) );

But the same errors!

Reason: