cbot stops by itelsf after upgrade to 4.2

Created at 30 Aug 2022, 18:51
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!
TR

tradersanga

Joined 13.08.2022

cbot stops by itelsf after upgrade to 4.2
30 Aug 2022, 18:51


 

After upgrading to 4.2 from 4.1, my cbot now breaks and I get this error

30/08/2022 15:03:14.337 | cbotname, USDX, m15] crashed with error "Crashed in Positions.Opened event with NullReferenceException: Object reference not set to an instance of an object."

Here are the related code

        void Position_Opens(PositionOpenedEventArgs obj)
        {

            if (obj.Position.Label.Equals(_longlabel))
                _longopen = true;

            if (obj.Position.Label.Equals(_shortlabel))
                _shortopen = true;

        }

        protected override void OnStart()
        {
            Initialize();
            Positions.Opened += Position_Opens;
            Positions.Closed += Position_Closes;
            adx = Indicators.DirectionalMovementSystem(ADXPeriod);
        }

 

The problem doesnt happen onstart but it seems its related to positions

I have been using this cbot for a year without issues but just upgraded to 4.2 and since then it just stops by itself and I have to manually restart every day, sometimes multiple times a day.

Please is there something I need to change in the cbot?

 

Urgent help appreciated


@tradersanga
Replies

PanagiotisCharalampous
31 Aug 2022, 08:39

Hi tradersanga,

Label became nullable, hence you need to check if it is null first before using it

 if (obj.Position.Label != null && obj.Position.Label.Equals(_longlabel))

Hope this helps

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

tradersanga
02 Sep 2022, 14:55

RE:

Hi Panagiotis,

 

This worked so beautifully well, and the cbot doesnt stop anymore.

Thanks so much!

 


@tradersanga