when switching a position, stop and target get lost.
What is the best synchronus way to reattach stop and target, using CTrade::PositionModify ?
So the squence is:
Unfortunately, even OrderSend is successfull, CTrade::PositionModify fails with error invalid stops.
It seems PositionModify call is to early.
How to wait for new position in order to be able to attach stop and target ?
I am not sure that I understood sorry ...
Personally I had some issue with old builds of MT5: when i wanted to open new position to already existing one so I was losing stop loss and take profit values, and I had to place sl/tp once again. I do not have this issue for now ... may be - it was fixed with new build of MT5, or MT5 starts to like me :) who knows ... But I created this small video about what i am doing in this case:
yes can confirm this issue and also that it has gone.
My situation is different: I am long, now i switch to short. Stop and loss are gone, which is ok. Now i need a most save and fast method to reapply stop and target
(of my own choice) right after i switched position. Directly after OrderSend (when position was switched) i can't do this, because CTrade::PositionModifiy(mySymbol,myNewStop,myNewTarget)
always fails. I guess because at this time, internally the new position is not yet "established".
So how to do this ?
Have a solution:
1. Send order that switches positions
2. Wait for event OnTradeTransaction (so new position established)
3. Call CTrade::PositionModify (symbol_of_transaction,new_stop,new_target)
(You need to wait for step 2. )
How is that supposed to help to solve chinaski's problem ?
Yes you have to wait, and you also have to check SymbolInfoInteger's SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL when modifying. But there's some report that wait does not always solve this problem, so after opening position, it's better to return, and check if position is already opened using PositionSelect(), then modify.