Download MetaTrader 5

Switch Position with stop and target

To add comments, please log in or register
1000 paid orders are executed in Freelance service. Sign up!
chinaski
890
chinaski 2013.02.25 15:09 

Hello,

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:

 

1. OrderSend

2... ? 

3.  CTrade::PositionModify

 

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 ?

Thank you 

 

Thank you 

Sergey Golubev
Moderator
93762
Sergey Golubev 2013.02.25 15:36  

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:



chinaski
890
chinaski 2013.02.25 15:47  
newdigital:

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:



Hello,

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 ? 

chinaski
890
chinaski 2013.02.25 16:07  

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. )

Sergey Golubev
Moderator
93762
Sergey Golubev 2013.02.25 18:54  
As I remembner - I bought in the Market some very cheap EA which is placing stop loss/take profit automatically for any market position ...

phi nuts
2184
phi nuts 2013.02.26 03:32  
newdigital:
As I remembner - I bought in the Market some very cheap EA which is placing stop loss/take profit automatically for any market position ...

How is that supposed to help to solve chinaski's problem ?


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. )

 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.

 

To add comments, please log in or register