How to return new SL

 

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;

 
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?

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

 
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"?

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

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

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

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.

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

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