Could not find a position

Created at 08 Dec 2023, 15: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!
GA

GabrielContiniDallmann

Joined 22.09.2017

Could not find a position
08 Dec 2023, 15:50


Hi!

I'm trying to modify a position in my cBot, but when this was triggered by a pending order, i can't find the position and it gives me a error: Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object.

            var position = Positions.Find(("Trade_" + Chart.SymbolName), Chart.SymbolName);

            // Proteger operação
            if (position.TradeType == TradeType.Sell && protegido == false && ((entryPrice - Bars.ClosePrices[Bars.Count -1]) / Symbol.PipSize) >= pips/2)
            {
                var realEntryPrice = LastResult.Position.EntryPrice;
                var takeProfit = LastResult.Position.TakeProfit;
                

                // HERE WHERE GENERATES THE ERROR
                ModifyPosition(position, realEntryPrice, takeProfit);
                protegido = true;
                
            }

Its weird because if i execute the same code and the order was a marketorder the code works fine.

Could you help me with this?


@GabrielContiniDallmann
Replies

PanagiotisCharalampous
09 Dec 2023, 06:00

Hi there,

Please share the complete cBot code so that we can reproduce this behavior.

Best regards,

Panagiotis


@PanagiotisCharalampous