Download MetaTrader 5

How to modify a specific Order`s Stop Loss?

To add comments, please log in or register
ananth
17
ananth  

Hi all,

I just started looking up MQL 5 about a week ago. I have worked on MQL 4, about 7 years ago. Seems like loads of changes!. 

In MQL 4, we simply had to select order from a collection of orders using the order ticket and modify it`s property. But, i`ve been struggling to wrap my brain around MQL 5, as we have Positions and Deals. 

Is there a way to modify a specific Order from a collection of Orders inside a position?

Example:

I opened 3 Buy orders using:

t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 1"); 
t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 2");
t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 3");

 

Now, I would like to Modify the stop loss of Order 2 which has the comment "Buy Deal - 2".

I`ve tried OrderModify() and PositionModify(). Unfortunately, neither works.

Any help or direction will be appreciated.

Thank you!. 

 

--------------------------------------------

Edit: Both OrderSend() with request.action=TRADE_ACTION_SLTP; and PositionModify() yield the same result :( Seems like MT5 is disappointing to me. The only option i am left with is to open an opposite deal just to nullify a previously opened deal. Why can`t they make it simpler, i wonder... 

Alain Verleyen
Moderator
31204
Alain Verleyen  
ananth:

Hi all,

I just started looking up MQL 5 about a week ago. I have worked on MQL 4, about 7 years ago. Seems like loads of changes!. 

In MQL 4, we simply had to select order from a collection of orders using the order ticket and modify it`s property. But, i`ve been struggling to wrap my brain around MQL 5, as we have Positions and Deals. 

Is there a way to modify a specific Order from a collection of Orders inside a position?

Example:

I opened 3 Buy orders using:

t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 1"); 
t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 2");
t_Trade.Buy(0.1, _Symbol, longTradePrice, longTradeSL, 0, "Buy Deal - 3");

 

Now, I would like to Modify the stop loss of Order 2 which has the comment "Buy Deal - 2".

I`ve tried OrderModify() and PositionModify(). Unfortunately, neither works.

Any help or direction will be appreciated.

Thank you!. 

 

--------------------------------------------

Edit: Both OrderSend() with request.action=TRADE_ACTION_SLTP; and PositionModify() yield the same result :( Seems like MT5 is disappointing to me. The only option i am left with is to open an opposite deal just to nullify a previously opened deal. Why can`t they make it simpler, i wonder... 

You have to use Pending Order, for your example, set a Sell_Stop order with 0.1 as volume and longTradePrice-longTradeSL as price.

Another option is to memorize your orders in your EA and track the price to close an order when price reach a stoplevel.

ananth
17
ananth  
angevoyageur:

You have to use Pending Order, for your example, set a Sell_Stop order with 0.1 as volume and longTradePrice-longTradeSL as price.

Another option is to memorize your orders in your EA and track the price to close an order when price reach a stoplevel.

Thanks for your solution angevoyageur. 

 So, If i have to modify a single property of a single open deal in out of many open deals for a single _Symbol, the closest approach for this would be to create a pending order, modify it on and on and on until my requirement is dynamically met.

The other option may not suit my requirement as i need to Trail Stop Loss only for a single deal "Buy Deal - 2" in my above example.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
Alain Verleyen
Moderator
31204
Alain Verleyen  
ananth:

Thanks for your solution angevoyageur. 

 So, If i have to modify a single property of a single open deal in out of many open deals for a single _Symbol, the closest approach for this would be to create a pending order, modify it on and on and on until my requirement is dynamically met.

The other option may not suit my requirement as i need to Trail Stop Loss only for a single deal "Buy Deal - 2" in my above example.

Modify a pending order isn't different to modify an stoploss order. The 2 options are valid for your requirements. The only difference is that one side you manage an order sent to the trading server and in the other you manage everything in your ea and close a deal when you requirements are meets.
ananth
17
ananth  
angevoyageur:
Modify a pending order isn't different to modify an stoploss order. The 2 options are valid for your requirements. The only difference is that one side you manage an order sent to the trading server and in the other you manage everything in your ea and close a deal when you requirements are meets.
Yes, i understand your viewpoint now!. Thanks for the clarification. I appreciate it!.
Alain Verleyen
Moderator
31204
Alain Verleyen  
ananth:
Yes, i understand your viewpoint now!. Thanks for the clarification. I appreciate it!.
You are welcome.
To add comments, please log in or register