CRASHES: Positions.Where(x => x.Symbol == Symbol).Where(x => x.Label.Contains('_')).Count()

Created at 31 Oct 2023, 12:31
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!
CH

ChrisSpire

Joined 12.12.2022

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);

 


@ChrisSpire
Replies

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

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