need some help with EA

 
hello how can i make a code which will move my SL level to break even after X amount of pips in the direction of TP ?? PLEASE HELP :) thanks !
 
sergeyrar wrote >>
hello how can i make a code which will move my SL level to break even after X amount of pips in the direction of TP ?? PLEASE HELP :) thanks !

The article discuses trailings stops

https://www.mql5.com/en/articles/1491

whocares

 
whocares wrote >>

The article discuses trailings stops

https://www.mql5.com/en/articles/1491

whocares

thanks alot

 
sergeyrar:

thanks alot

Sergey,

do not break your head.

This is the code, copy, paste and here you go


int TrailingStop;

for(int b=0;b<OrdersTotal();b++)
{
if(OrderSelect(b,0,0))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
if(Bid-OrderOpenPrice()>=Point*TrailingStop)
if(OrderStopLoss()<Bid-Point*TrailingStop)
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);
if(OrderType()==OP_SELL)
if(OrderOpenPrice()-Ask>=Point*TrailingStop)
if(OrderStopLoss()>Ask+Point*TrailingStop)
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Yellow);
}
}

 
Brygada wrote >>

Sergey,

do not break your head.

This is the code, copy, paste and here you go

int TrailingStop;

for(int b=0;b<OrdersTotal();b++)
{
if(OrderSelect(b,0,0))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
if(Bid-OrderOpenPrice()>=Point*TrailingStop)
if(OrderStopLoss()<Bid-Point*TrailingStop)
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);
if(OrderType()==OP_SELL)
if(OrderOpenPrice()-Ask>=Point*TrailingStop)
if(OrderStopLoss()>Ask+Point*TrailingStop)
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Yellow);
}
}

thanks man !!!

but i need it for OP_SELLSTOP, OP_BUYSTOP - is it the same ?

will it work for these kind of orders ?

 

I used it for already opened positions.

Hope it should work for pending orders, just try.

 
Brygada wrote >>

I used it for already opened positions.

Hope it should work for pending orders, just try.

yeah it works good !

thank you

 
My pleasure to help.
Reason: