[invalid stops] during modification - page 2

 
You need to do it for both, SL and TP.

How about applying some thought to your problem. Don't expect others to do your thinking.


 

Don't forget to normalize prices and compare normalized prices always.

A lot of times i seen problems comparing not normalized prices even if they "looks the same", actually there were not.

In addition to this, you also need to check Stop Levels of the symbol on which the position belong and also compare the new SL/TP with bid/ask price (depending on the position type if buy or sell).

Not doing a correct error handling for this thing means to risk to have EA sending a lot of bad requests to broker that will put your account into hyperactive and then disable autotrading on that. Pay attention.

 
Dominik Christian Egert #:
You need to do it for both, SL and TP.

How about applying some thought to your problem. Don't expect others to do your thinking.


I did that for 4 prices

TPbuy changes ---> modify TPBuy

TPSell Changes ---> modify TPSell

SLBuy Changes ---> modify SLBuy

SLSell Changes ---> modify SLSell

 
Fabio Cavalloni #:

Don't forget to normalize prices and compare normalized prices always.

A lot of times i seen problems comparing not normalized prices even if they "looks the same", actually there were not.

I think you're right, comparing between non-normalized with real price will give different values but will be the same after modification.

Fabio Cavalloni #:

In addition to this, you also need to check Stop Levels of the symbol on which the position belong and also compare the new SL/TP with bid/ask price (depending on the position type if buy or sell).

yes, I put Ask & Bid as bandwidth for TP's and SL's.

Fabio Cavalloni #:

Not doing a correct error handling for this thing means to risk to have EA sending a lot of bad requests to broker that will put your account into hyperactive and then disable autotrading on that. Pay attention.

I already run this EA and a testing duration on a demo account with five symbols

any way, I will try your devices about normalizing my values and I appreciate that.

Thank you 

 
Fabio Cavalloni #:

Don't forget to normalize prices and compare normalized prices always.

A lot of times i seen problems comparing not normalized prices even if they "looks the same", actually there were not.

In addition to this, you also need to check Stop Levels of the symbol on which the position belong and also compare the new SL/TP with bid/ask price (depending on the position type if buy or sell).

Not doing a correct error handling for this thing means to risk to have EA sending a lot of bad requests to broker that will put your account into hyperactive and then disable autotrading on that. Pay attention.

I tried this code:

if (  TPBuy != PositionGetDouble (POSITION_TP)  )  ModifyBuy  (SymbArray,PositionGetDouble (POSITION_SL),TPBuy);

I put the same method for  TPSell, SLBuy and SLSell (sometimes I change TP only or SL only)

and:

if ( SLBuy  >Bid && SLBuy  <Ask ) SLBuy  = Bid;
if ( TPBuy  >Bid && TPBuy  <Ask ) TPBuy  = Ask;
if ( SLSell <Bid && SLSell >Ask ) SLSell = Ask;
if ( TPSell <Ask && TPSell >Bid ) TPSell = Bid;

while SLBuy, SLSell, TPBuy, SLSell, Ask and Bid are normalized double after calculation values

Wihle:

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 the same with ModifySell

but the result is:


2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:00   failed modify #6 sell 0.01 EURUSD sl: 1.23615, tp: 1.22465 -> sl: 1.23485, tp: 1.22468 [Market closed]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:00   CTrade::OrderSend: modify position #6 EURUSD (sl: 1.23485, tp: 1.22468) [market closed]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:20   failed modify #6 sell 0.01 EURUSD sl: 1.23615, tp: 1.22465 -> sl: 1.23485, tp: 1.22468 [Market closed]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:20   CTrade::OrderSend: modify position #6 EURUSD (sl: 1.23485, tp: 1.22468) [market closed]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:40   failed modify #6 sell 0.01 EURUSD sl: 1.23615, tp: 1.22465 -> sl: 1.23435, tp: 1.22468 [Invalid stops]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:40   CTrade::OrderSend: modify position #6 EURUSD (sl: 1.23435, tp: 1.22468) [invalid stops]

2022.01.25 04:30:32.395 Core 1 2021.01.05 00:00:59   failed modify #6 sell 0.01 EURUSD sl: 1.23615, tp: 1.22465 -> sl: 1.23451, tp: 1.22468 [Invalid stops]


 
Read your log files.

You seem still to demand people to do the thinking for you, don't you.

Look at what you are doing. Sell position, SL lower than your TP, why?

I don't think this will work.



EDIT:

Ohh, I am sorry, I mistakenly read the tp value wrong...

Therefore, I cannot help you with the issue. I will pass on this....

 
Dominik Christian Egert #:
Read your log files.

You seem still to demand people to do the thinking for you, don't you.

Look at what you are doing. Sell position, SL lower than your TP, why?

I don't think this will work.



EDIT:

Ohh, I am sorry, I mistakenly read the tp value wrong...

Therefore, I cannot help you with the issue. I will pass on this....

Thank you.

Reason: