# Break even / trailing stop

330

Hi guys,

If I place an order of let's say take profit 500 and stop loss 100. I want the order to break even when it gets to 100 profit (which is easy enough to code) however, I want the stop loss to move up every 100 pips (not trail) by 100 pips. So it will take incremental steps towards the take profit. In other words it must "break even" every 100 pips adding an additional 100 pips to the stop loss. I have coded the first step but not sure how to make it move step by step. Here is my break even code:

```void MoveToBreakeven()                 //Breakeven function
{
for(int b=OrdersTotal()-1; b >= 0; b--)
{
if(OrderMagicNumber()==MagicNumber)      //correct order
if(OrderSymbol()==Symbol())            //correct pair
if(OrderOpenPrice()>OrderStopLoss())
if(Bid-OrderOpenPrice()>WhenToMoveToBE*Point)    //how far has the bid moved from opening
}

for(int s=OrdersTotal()-1; s>=0; s--)
{
if(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol())
if(OrderType()==OP_SELL)
if(OrderOpenPrice()<OrderStopLoss())
}
}
```

If there is any way to edit it to make it move step by step that would help a lot!

15554

```if(Bid-OrderOpenPrice()>WhenToMoveToBE*Point)    //how far has the bid moved from opening
What you wrote was a trailing SL. What you need is two critera A) below BE move when market reaches 100 pips. B) above(at) BE move when market reaches 200 pips above SL.
330

WHRoeder:
What you wrote was a trailing SL. What you need is two critera A) below BE move when market reaches 100 pips. B) above(at) BE move when market reaches 200 pips above SL.
Okay, that logic helps.. So something like this...
```void MoveToBreakeven()                 //Breakeven function
{
for(int b=OrdersTotal()-1; b >= 0; b--)
{
if(OrderMagicNumber()==MagicNumber)      //correct order
if(OrderSymbol()==Symbol())            //correct pair
if(Bid-OrderOpenPrice()>WhenToMoveToBE1*Point)    //how far has the bid moved from opening
if(OrderOpenPrice()>OrderStopLoss())
if(Bid-OrderOpenPrice()>WhenToMoveToBE2*Point)
if(OrderOpenPrice()>OrderStopLoss())
}

for(int s=OrdersTotal()-1; s>=0; s--)
{
if(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol())
if(OrderType()==OP_SELL)
if(OrderOpenPrice()<OrderStopLoss())
if(OrderOpenPrice()<OrderStopLoss())
}
}```
330

WHRoeder:
What you wrote was a trailing SL. What you need is two critera A) below BE move when market reaches 100 pips. B) above(at) BE move when market reaches 200 pips above SL.

Okay this works:

```void MoveToBreakeven()                 //Breakeven function
{
for(int b=OrdersTotal()-1; b >= 0; b--)
{
if(OrderMagicNumber()==MagicNumber)      //correct order
if(OrderSymbol()==Symbol())            //correct pair
if(OrderOpenPrice()>OrderStopLoss())
if(Bid-OrderOpenPrice()>WhenToMoveToBE1*Point)    //how far has the bid moved from opening

if(Bid-OrderOpenPrice()>WhenToMoveToBE2*Point)
` if(Bid > OrderStoploss() +step*Point)   `