Could not find a position
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?
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