How to return new SL

To add comments, please log in or register
Sonima
25
Sonima  

Hello!

In an EA, I modify the SL and then I want to return the new stop loss as the following:

current_SL = OrderStopLoss();

But I got the original SL (before modification) into the current_SL

How can return the new OrderStopLoss() into the current_SL

Thanks.

PS: I defined the current_SL as double

double current_SL = 0;

Fernando Morales
729
Fernando Morales  
Sonima:

Hello!

In an EA, I modify the SL and then I want to return the new stop loss as the following:

current_SL = OrderStopLoss();

But I got the original SL (before modification) into the current_SL

How can return the new OrderStopLoss() into the current_SL

Thanks.

PS: I defined the current_SL as double

double current_SL = 0;

How do you change the SL of an open/pending order?

Keith Watford
Moderator
14468
Keith Watford  
Sonima:

Hello!

In an EA, I modify the SL and then I want to return the new stop loss as the following:

current_SL = OrderStopLoss();

But I got the original SL (before modification) into the current_SL

How can return the new OrderStopLoss() into the current_SL

Thanks.

PS: I defined the current_SL as double

double current_SL = 0;

Select the order after modifying the order to update OrderStopLoss()

Sonima
25
Sonima  
Keith Watford:

Select the order after modifying the order to update OrderStopLoss()

Hello and thanks for your reply.

What do you mean by "Select the order after modifying the order"?

whroeder1
17926
whroeder1  
Sonima: How can return the new OrderStopLoss() into the current_SL
You asked how to get the new SL. What part of "Select the order after modifying the order" was unclear?
Sonima
25
Sonima  
Hi!
whroeder1:
You asked how to get the new SL. What part of "Select the order after modifying the order" was unclear?

Hello!

I don't understand how should I select the order?! There is only one order.

whroeder1
17926
whroeder1  
Perhaps you should read the manual.
The function selects an order for further processing.
          OrderSelect - Trade Functions - MQL4 Reference
Fernando Morales
729
Fernando Morales  

and don't forget OrderModify()


https://docs.mql4.com/trading/ordermodify

OrderModify - Trade Functions - MQL4 Reference
OrderModify - Trade Functions - MQL4 Reference
  • docs.mql4.com
[in]  Arrow color for StopLoss/TakeProfit modifications in the chart. If the parameter is missing or has CLR_NONE value, the arrows will not be shown in the chart. Open price and expiration time can be changed only for pending orders. If unchanged values are passed as the function parameters, the error...
Sonima
25
Sonima  

Guys,

Many thanks for your time and hints.

I didn't succeed. Would you be kind and help me, I am not good in this.

Here is a part of the code:

bool BE = False;
double Old_ClosePrice=0;

int start() {
   for (int lpos0 = 0; lpos0 < OrdersTotal(); lpos0++) {
       Result = OrderSelect(lpos0, SELECT_BY_POS, MODE_TRADES);
	   
       if (OrderStopLoss() < OrderOpenPrice()) {
        Result = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, CLR_NONE);
        BE = True;
        Old_ClosePrice = iClose(OrderSymbol(), 0, 0);
		}

    }
}


I want to return close price (in this case) to the "Old_ClosePrice" and change the BE from false to true. However "Old_ClosePrice" returns zero and BE returns false!

Please advise.

Many thanks.

Fernando Morales
729
Fernando Morales  
Sonima:

Guys,

Many thanks for your time and hints.

I didn't succeed. Would you be kind and help me, I am not good in this.

Here is a part of the code:


I want to return close price (in this case) to the "Old_ClosePrice" and change the BE from false to true.

Please advise.

Many thanks.

That code will never work, but you are getting close

Before using any Order... function like OrderModify() you must activate OrderSelect()

Give it another try. As starting point use the code example from the link to OrderModify() documentation page.

Hint: You need to create a FOR loop for checking all trades open by means of OrderSelect()

Sonima
25
Sonima  
Fernando Morales:

That code will never work, but you are getting close

Before using any Order... function like OrderModify() you must activate OrderSelect()

Give it another try. As starting point use the code example from the link to OrderModify() documentation page.

Hint: You need to create a FOR loop for checking all trades open by means of OrderSelect()

Hello again, thanks for your reply.

As I mentioned, this a part of the code and except those two problems, it works fine.

I update the code in the above post (my bad).

12
To add comments, please log in or register