Sperate Stop Loss and Break Even

Created at 18 Aug 2016, 18:50
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AR

armstr.tradie

Joined 30.03.2016

Sperate Stop Loss and Break Even
18 Aug 2016, 18:50


I'm asking if it is possible to have a separate break even or at least a non-trailing break-even at the start that is above the entry price and to have a normal trailing stop loss later in a cbot robot?

Essentially I would like to have trades with a break-even that is set with a trigger of say 5 pips with the break-even set at 1 pip above the entry price. Thus far I have only been able to set the break-even at the entry price, but because of the spread I'm still in negative net profit at times. Is it possible to have it set at least 1 pip above? Is it possible to have a non-trailing break-even or stop loss at the start and only have the trailing stop loss start at another triggered pip level?

 

Here is an my code for the my break even and trailing stop.

private void MoveToBreakEven()
        {
            foreach (var position in Positions.FindAll(label, Symbol))
            {
                if (position.StopLoss != position.EntryPrice)
                {
                    if (position.Pips >= 5)
                    {
                        ModifyPosition(position, position.EntryPrice, position.TakeProfit);
                    }
                }
            }
        }

        private void SetTrailingStop()
        {
            var sellPositions = Positions.FindAll(label, Symbol, TradeType.Sell);

            foreach (Position position in sellPositions)
            {
                double distance = position.EntryPrice - Symbol.Ask;

                if (distance < Trigger * Symbol.PipSize)
                    continue;

                double newStopLossPrice = Symbol.Ask + TrailingStop * Symbol.PipSize;

                if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
                    ModifyPosition(position, newStopLossPrice, position.TakeProfit);
            }

            var buyPositions = Positions.FindAll(label, Symbol, TradeType.Buy);

            foreach (Position position in buyPositions)
            {
                double distance = Symbol.Bid - position.EntryPrice;

                if (distance < Trigger * Symbol.PipSize)
                    continue;

                double newStopLossPrice = Symbol.Bid - TrailingStop * Symbol.PipSize;
                if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
                    ModifyPosition(position, newStopLossPrice, position.TakeProfit);
            }
        }

One thing I attempted do where it says:

ModifyPosition(position, position.EntryPrice, position.TakeProfit);

was to modify it to this:

ModifyPosition(position, position.EntryPrice + (Symbol.Pipsize * 1), position.TakeProfit);

It appeared to work at first. But, it kept repeating the "BAD_STOPS" error message and also when the trailing stop-loss was triggered it appeared to constantly jump between the two stop losses and cause errors.

 

I hope any one can help out here, and thanks in advance to those who can help.


@armstr.tradie
Replies

... Deleted by UFO ...

kricka
18 Aug 2016, 20:15

Break-even

It is possible to solve. The issue is that the API does not really explain how to do it. There are some threads that can help you out though. Search for break even and move the stop loss, and so forth to get some bits of information and then you have to puzzle it all together and test it out by the  trial and error method to get it right.

The Market Order 3.0 shows that it can be done, have a look at the information and if you choose you can download and test it on a demo or live account.

Information and download link: Market Order 3.0


@kricka

armstr.tradie
19 Aug 2016, 05:56

RE:

lucian said:

First try to change:

private void MoveToBreakEven()
        {
            foreach (var position in Positions.FindAll(label, Symbol))
            {
                if (position.StopLoss != position.EntryPrice)
                {
                    if (position.Pips >= 5)
                    {
                        ModifyPosition(position, position.EntryPrice, position.TakeProfit);
                    }
                }
            }
        }

in :

private void MoveToBreakEven()
        {
            foreach (var position in Positions.FindAll(label, Symbol,TradeType.Sell))
            {
                if (position.StopLoss != position.EntryPrice)
                {
                    if (position.Pips >= 5)
                    {
                        ModifyPosition(position, position.EntryPrice-(Symbol.PipSize*1), position.TakeProfit);
                    }
                }
            }
        }

            foreach (var position in Positions.FindAll(label, Symbol,TradeType.Buy))
            {
                if (position.StopLoss != position.EntryPrice)
                {
                    if (position.Pips >= 5)
                    {
                        ModifyPosition(position, position.EntryPrice+(Symbol.PipSize*1), position.TakeProfit);
                    }
                }
            }
        }

 

 

Thanks Lucian. It appeared to work well but there seems to be an issue with the triggers I think. It worked as intended when it got to the first trigger for the break-even, but when it reached the second trigger that got the trailing stop loss going the stop loss began to jump to and from the new stop-loss price to the old one with each movement of the bid and ask price.

I wonder if a jumping stop may be the only way out of this issue. Or is there a way to have another stop-loss in same bot - kinda like the advanced take profit? I think the problem is that it has the same stop-loss following two different triggers and it doesn't know which one to follow. Could one make another stop - so you have say "SL" and "SL2"? 

Again any help on this would be greatly appreciated. Thank you. 


@armstr.tradie