Update to Breakeven Code Snippet

Created at 20 Jan 2020, 10:17
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!
Symposium's avatar

Symposium

Joined 16.07.2018

Update to Breakeven Code Snippet
20 Jan 2020, 10:17


Hi Panagiotis, The BE code below only activates on Buy positions. Can you please revise the code so this can be be activated by both Buy and Sell positions when added to a cBot. 

This maybe helpful for a number of Ctrader algo builders, so it's best to be out in the forum for community use. Cheers TWB.

private void GoToBreakEven()
        {
            var position = Positions.Find(InstanceName, SymbolName);
            if (position != null)
            {
                var entryPrice = position.EntryPrice;
                var distance = 0.0;
                var adjEntryPrice = position.TradeType == TradeType.Buy ? entryPrice + ExtraPips * Symbol.PipSize : entryPrice - ExtraPips * Symbol.PipSize;
                if (position.TradeType == TradeType.Buy)
                    distance = Symbol.Bid - entryPrice;
                else
                    distance = entryPrice - Symbol.Ask;

                if (distance >= Trigger * Symbol.PipSize && position.StopLoss != adjEntryPrice)

                    ModifyPosition(position, adjEntryPrice, TakeProfitPips);
                {
                }

 


@Symposium
Replies

PanagiotisCharalampous
20 Jan 2020, 10:22

Hi Symposium,

Please post the complete cBot code so that I can have a look.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous