Adjust position when position is up by certain amount of pips from executed order

Created at 13 Aug 2020, 16:51
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!
SA

samuelbreezey

Joined 10.04.2019

Adjust position when position is up by certain amount of pips from executed order
13 Aug 2020, 16:51


Hi All

I have my stop loss automatically set and I wanted to know how to adjust an open position if the initial risk in pips (open price - stop loss) is above 3%. I am having trouble incorporating the pip value from the order into the foreach (var position in Positions) section of code.

I assume slPriceS & slPriceB change each time which is why my bot isn't working how I would like.

If there is a better way to do this, i would love to hear your thoughts :)

Many thanks
Sam


@samuelbreezey
Replies

samuelbreezey
15 Aug 2020, 11:06

RE:

samuelbreezey said:

Hi All

I have my stop loss automatically set and I wanted to know how to adjust an open position if the initial risk in pips (open price - stop loss) is above 3%. I am having trouble incorporating the pip value from the order into the foreach (var position in Positions) section of code.

I assume slPriceS & slPriceB change each time which is why my bot isn't working how I would like.

If there is a better way to do this, i would love to hear your thoughts :)

Many thanks
Sam

Figured out that I can adjust the order when position is in profit by certain percentage using the following:

 var PositionPnL = Math.Round(100 * Positions.Sum(t => t.NetProfit) / Account.Balance, 1);

Full code:

foreach (var position in Positions.FindAll(InstanceName, SymbolName))
            {
                var shortPosition = Positions.Find(InstanceName, SymbolName, TradeType.Sell);
                var longPosition = Positions.Find(InstanceName, SymbolName, TradeType.Buy);
                var shortPositionsCount = Positions.Count(p => p.TradeType == TradeType.Sell);
                var longPositionsCount = Positions.Count(p => p.TradeType == TradeType.Buy);
                var PositionPnL = Math.Round(100 * Positions.Sum(t => t.NetProfit) / Account.Balance, 1);
                if (position.StopLoss != position.EntryPrice && longPositionsCount > 0)
                {
                    if (PositionPnL >= 0.5 && PositionPnL < 3)
                    {
                        ModifyPosition(position, position.EntryPrice, position.TakeProfit);
                    }
                }
                else if (position.StopLoss != position.EntryPrice && shortPositionsCount > 0)
                {
                    if (PositionPnL >= 0.5 && PositionPnL < 3)
                    {
                        ModifyPosition(position, position.EntryPrice, position.TakeProfit);
                    }
                }

            }

 


@samuelbreezey