Why do my cbot stop runing ?

Created at 27 Jul 2018, 02:39
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!
MI

MinMin

Joined 23.07.2018

Why do my cbot stop runing ?
27 Jul 2018, 02:39


I writed some code something like that


 protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var SoLenh = Positions.Count(x => x.SymbolCode == Symbol.Code);

         }

if (RSI > 65)
            {
                if (SoLenh < 3)
                    ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
                if (longPosition != null)
                    ClosePosition(longPosition);
            }
else if (RSI < 35)
            {
                if (SoLenh < 3)
                    ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
                if (shortPosition != null)
                    ClosePosition(shortPosition);
            }
else if (RSI < 30 && shortPosition != null)
                ClosePosition(shortPosition);
else if (RSI > 70 && longPosition != null)
                ClosePosition(longPosition);

It can runing without any errors but after few time it stop and the log showed:


27/07/2018 01:09:42.191Crashed in Positions.Opened with NullReferenceException: Object reference not set to an instance of an object.

27/07/2018 01:09:42.238cBot "New cBot" was stopped for EURCHF, m2.
 

Please help I cannot know when it stop runing to start it again!

 

Thanks so much!


@MinMin
Replies

PanagiotisCharalampous
27 Jul 2018, 09:53

Dear Trader,

The cBot crashes in a function that has not been provided in the code sample above. Please share the full cBot code so that we can advise you on what the issue might be.

Best Regards,

Panagiotis


@PanagiotisCharalampous