When StopLoss closes a trade

 

What is the best method to code for an event of when the MT4 closes a trade based on a set stoploss. For example, trade A opens, a stoploss is set, trade B opens a stop loss is set, when a stop loss is hit, I want to move the stop loss of the remaining open trades to the price where that stop loss occured. How would I do that?

 

I don't know about best method but here's what comes to mind for me. You may need to do additional things like making sure the dynamic_stoploss is not too close to current bid/ask and also you may need to differ buy order from sell orders because you don't want to attempt setting stoploss above buy order current price for instance.

if order_total_varable < order_total....tells it an order just closed.

for i=order_history_totals; i>=0; i--

if order_select i by position / history == true

if order take_profit < 0 

dynamic_stoploss = order_stop_loss

break; 

+------------------------------------------------

if order_totals > 0 .... wanna make sure you have open orders

for j=order_active_totals; j>=0; j--

if order_select i by position / trades == true

ordermodify (order_stop_loss =  dynamic_stoploss)

 

Cool, that is just what I did in a generic round about way. The concept is good. Thanks.