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

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