Change SL to TP once it's hit and set new TP

 

Hi there folks,

I am trying to do the following:

- once trade has hit take profit 1

- set stop loss to current market price (this won't be possible since TP and SL must differ from market price, but it should be possible to make the EA close the trade, correct?)

AND 

  - set new take profit to desired value (and this time close the trade as a real take profit)

 

How difficult is it to do something like this? I've look around here, but don't really know where to start it..

Thanks 

 
metacooler:
 

How difficult is it to do something like this? I've look around here, but don't really know where to start it..

It is depending on your will to learn. For many guys here it is not difficult at all.
Take the time to read and understand the Book and you don't think that's difficult anymore.

 
metacooler:

I am trying to do the following:

- once trade has hit take profit 1

Once the trade hits the take profit, the trade is closed automatically by the broker.
 
WHRoeder:
Once the trade hits the take profit, the trade is closed automatically by the broker.


Yes, that's why step 1 and 2 must be controlled by the EA and not send the order to the broker..

That's where lies my doubt 

 
metacooler:


Yes, that's why step 1 and 2 must be controlled by the EA and not send the order to the broker..

That's where lies my doubt 

So you are looking to code a leading TP . . .  bit like a trailing SL but the other way round,  shouldn't be difficult,  I'm sure it has been done before.
 

By looking at a few different trailing stop and breakeven EA's I think I'll be able to do this.

Once it's done I'll post it here, in case anyone is interested.

Thanks for the suggestions 

 

Till now I modified my inital take profit to take profit 2 (the latest target) and I want to set a trailing stop starting at target 1 and make the stop loss move at each step.

How can I do that? My current trailing step code is the following:

void MoveTrailingStop()
{
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber() == MagicNumber)
      {
         if(OrderType()==OP_BUY)
         {
            if(TrailingStop>0 && Ask>=(TrailingStop*Point)) 
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Green);
                  return(0);
               }
            }
         }
         else 
         {
            if(TrailingStop>0 && Bid<=(TrailingStop*Point))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red);
                  return(0);
               }
            }
         }
      }
   }
}

However, this current code sets a stop loss as soon as the trade is opened.

How can I make it trail only after trailingstop value has been reached?


Plus, how can  I make the EA control this, instead of sending the command to the broker, since there is a minimum difference of 5 pips to the market price.

 I didn't manage to do this afterall =/

 

Thank you 

 

edit:

I'll try to clarify what I want to do:

- trade is opened

-trade  moves 15 pips in my direction

- this value is locked (with a variable error margin)

- for every X pips that the price moves in my direction the stop loss is also moved X pips

 Example: trade opened at 1.0000. Price is now 1.0015 and stop loss has been activated at 1.0015 (only possible to be done via EA control due to order modification restrictions). price moved to 1.0017 (stop loss has been moved to 1.0017). Price retraces to 1.0016 and the order is closed.

I want it to have a very tight trailing stop. 

 
metacooler:

I'll try to clarify what I want to do:

- trade is opened

-trade  moves 15 pips in my direction

- this value is locked (with a variable error margin)

- for every X pips that the price moves in my direction the stop loss is also moved X pips

 Example: trade opened at 1.0000. Price is now 1.0015 and stop loss has been activated at 1.0015 (only possible to be done via EA control due to order modification restrictions). price moved to 1.0017 (stop loss has been moved to 1.0017). Price retraces to 1.0016 and the order is closed.

I want it to have a very tight trailing stop. 

Price is now 1.0015 and stop loss has been activated at 1.0015. <--that would just close the order. Also, when setting Stop-Order(s), you have to obey the broker's minimum stop-distance.
 
ubzen:
Price is now 1.0015 and stop loss has been activated at 1.0015. <--that would just close the order. Also, when setting Stop-Order(s), you have to obey the broker's minimum stop-distance.
Yup,  need to check that your order and any modifications and closes comply with what is written here:  Requirements and Limitations in Making Trades
 

Yes, I know that I need to comply with the limitations, as I said previously.

 That is why I want the EA to control the order closing, much like one would do if it was manual trading, instead of using MT4's trailing stop.

 Price is now 1.0015 and stop loss has been activated at 1.0014 (just one pip below, instead of the current price).

My intention is for the EA to take full control of the trade, instead of of sending the order modify to the broker. It should all be done locally. 

 
metacooler:

Yes, I know that I need to comply with the limitations, as I said previously.

 That is why I want the EA to control the order closing, much like one would do if it was manual trading, instead of using MT4's trailing stop.

 Price is now 1.0015 and stop loss has been activated at 1.0014 (just one pip below, instead of the current price).

My intention is for the EA to take full control of the trade, instead of of sending the order modify to the broker. It should all be done locally. 

In that case you'll need to save the close-price(s) for each order. Best place to save this information is to file. You could also save to static/global/global-variable-set depending.... on the number of orders.  
Reason: