CRASHES: Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label.Contains('_')).Count()
CRASHES: Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label.Contains('_')).Count()
31 Oct 2023, 12:31
Why in some cases (some instruments) it crashes and on other instruments it does not (?)
Probably crashes for instrumets where there are already some positions opened when I start cBot.
This is executed in “OnTick”. All other code is commented for the purpose of the test.
Print("Crash?");
var CrazyPositionsExist = Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label.Contains('_')).Count() > 0 ? true : false;
Print("CrazyPositionsExist = " + CrazyPositionsExist);
Replies
ChrisSpire
01 Nov 2023, 11:58
( Updated at: 02 Nov 2023, 06:49 )
RE: CRASHES: Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label.Contains('_')).Count()
Thank you!
PanagiotisChar said:
Hi there,
You should check if Label is null before calling it. See below
var CrazyPositionsExist = Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label != null && x.Label.Contains('_')).Count() > 0 ? true : false;
@ChrisSpire
PanagiotisChar
01 Nov 2023, 06:59 ( Updated at: 01 Nov 2023, 07:04 )
Hi there,
You should check if Label is null before calling it. See below
var CrazyPositionsExist = Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label != null && x.Label.Contains('_')).Count() > 0 ? true : false;
@PanagiotisChar