Modification of a SL and TP in the opened trade (EA code modification)

 

Hi there,

 

Could someon please give me some advice or help on this: I would like to add some function which will modify a SL and TP, when I have some profit in points. For example:

my EA opens LONG trade when EURUSD is 1,2000 -> SL 1,1900 and TP is 1,2100.

When EURUSD is 1,2050 i would like to have SL modified to 1,2040 and trailing stop for example 20pips and TP changed or remove.

 if(OrderSymbol() == Symbol() && OrderLucasX() == LucasX) 
         {
           int prevticket = OrderTicket();
           // long is open
           if(OrderType() == OP_BUY) 
             {
               // check profit 
               if(Bid > (OrderStopLoss() + (sl * 2  + spread) * Point)) 
                 {               
                   if(indi() > 0) 
                     { // reverse
                       ticket = OrderSend(Symbol(), OP_SELL, lots * 2, Bid, 3, Ask + sl * Point, Bid - tp * Point, "LT2", Lucas X, 0, Orange);
                       //----
                       if(ticket < 0) 
                           prevtime = Time[2];
                       else 
                           OrderCloseBy(ticket, prevticket, Green);   
                     } 
                   else 
                     { // trailing stop
                       if(!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - sl * Point, Bid - tp * Point, 0, Green)) 
                         {
                           prevtime = Time[2];
                         }
                     }
                 }  
               // short  is open
             } 

 Big Thank You for help

 
Karwats:

Hi there,

Could someon please give me some advice or help on this: I would like to add some function which will modify a SL and TP, when I have some profit in points. For example:

my EA opens LONG trade when EURUSD is 1,2000 -> SL 1,1900 and TP is 1,2100.

When EURUSD is 1,2050 i would like to have SL modified to 1,2040 and trailing stop for example 20pips and TP changed or remove.

 Big Thank You for help

Not sure what your problem is . . . . you seem to know what you want to do,  just get on and code it. 
 

You only show part of the code.

You should use OrderSelect() before calling OrderSymbol(), OrderTicket(), OrderType(), OrderStopLoss(), and OrderOpenPrice().

 
RaptorUK:
Not sure what your problem is . . . . you seem to know what you want to do,  just get on and code it. 


I know what I want, but don't know how to do it right.  How to add sth that will modify my order when for example it made some profit?
Reason: