Getting process was unexpectedly terminated error and bot was getting kicked out

Created at 01 Mar 2023, 12:23
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!
PR

prasanthtp

Joined 14.09.2022

Getting process was unexpectedly terminated error and bot was getting kicked out
01 Mar 2023, 12:23


Hi. I have a simple bot to place a market order, which I execute at different times. It is working fine sometimes, but sometimes it is giving errors. It looks like my bot is getting kicked out

My code

using cAlgo.API;

 [Robot(TimeZone = TimeZones.TasmaniaStandardTime, AccessRights = AccessRights.FullAccess)]
 public class SimpleOrder : Robot

{

protected override void OnStart()
{

Print("Trying to put order");
TradeResult result = ExecuteMarketOrder(TradeType.Sell, "AUDUSD", 100000, label: "SimpleOrder", takeProfitPips: 5, stopLossPips: null);

 Print("Order Execution Finished");

}

 }

I am getting the following error  in my log 


01/03/2023 12:45:01.286 | Trying to put order
01/03/2023 12:45:01.301 | Executing Market Order to Buy 100000 AUDUSD (TP: 5)
01/03/2023 12:45:08.022 | CBot instance [SimpleOrder , AUDUSD, h1] process was unexpectedly terminated.

 

Can you help me why I am not getting 100% success in this code. It is working some times but sometimes it is getting kicked out.

I am using a demo account. My ctrader version is 4.6.3.13401

Is it because I am using demo account and you guys impose limits on the number of orders that can be executed within a certain time period .

 

 

 


@prasanthtp
Replies

prasanthtp
02 Mar 2023, 09:33

event viewer for this error

when i looked at the windows event viewer, i can see following error;

 

Faulting application name: algohost.exe, version: 0.0.0.0, time stamp: 0x608e31d0
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc00000fd
Fault offset: 0x00007ffeeb094046
Faulting process id: 0x0x8924
Faulting application start time: 0x0x1D94C923A5C41CE
Faulting application path: C:\Users\name\AppData\Local\Spotware\cTrader\abb70432efbee65d18af69e79fe8efe1\app_4.6.3.13401\x64\algohost.exe
Faulting module path: unknown
Report Id: 142abf5b-e77c-4a33-9eff-55cbbbcec870
Faulting package full name:
Faulting package-relative application ID: 

 

 

Exception code: 0xc00000fd , I googled for it. it looks like a stack overflow error. any idea?


@prasanthtp

prasanthtp
08 Mar 2023, 12:17

I just upgraded to 4.7. Now when I execute the cbot. It is the same process was unexpectedly terminated error .  , I am getting a new error in windows event log.

Faulting application name: algohost.exe, version: 0.0.0.0, time stamp: 0x608e31d0

Faulting module name: System.Private.CoreLib.dll, version: 6.0.21.52210, time stamp: 0xf71d579

Exception code: 0xc00000f

Fault offset: 0x00000000001ab8c

Faulting process id: 0x0x250

Faulting application start time: 0x0x1D9519CD789C11

Faulting application path: C:\Users\prasa\AppData\Local\Spotware\cTrader\abb70432efbee65d18af69e79fe8efe1\app_4.6.4.13909\x64\algohost.ex

Faulting module path: C:\Users\prasa\AppData\Local\Spotware\dotnet\shared\Microsoft.NETCore.App\6.0.0\System.Private.CoreLib.dl

Report Id: 15e226f2-bfdd-49de-943d-11cd4ae6004

Faulting package full name

Faulting package-relative application I

D:5le801d3ication ID

 


@prasanthtp

prasanthtp
09 Mar 2023, 02:02 ( Updated at: 21 Dec 2023, 09:23 )

More info from debug System.Private.CoreLib

The exception is in System.Threading EventWaitHandle

 

 

 

 

 

 


@prasanthtp

prasanthtp
10 Mar 2023, 15:39 ( Updated at: 21 Dec 2023, 09:23 )

Hi

 

I am still getting this error. Please see my logs above


@prasanthtp

prasanthtp
14 Mar 2023, 12:49

Any updates?

Hi .  I have sent troubleshooting details via ctrader application as well. Any updates?


@prasanthtp

Spotware
14 Mar 2023, 12:58

Hi prasanthtp,

Unfortunately we were not able to identify the problem based on the troubleshooting information we received. If you are still able to reproduce the problem in 4.6.4, we would like to arrange a TeamViewer session so that our team can inspect the issue locally on your computer. If you can help us with this, please contact us at community@ctrader.com.

Best Regards,

cTrader Team


@Spotware

prasanthtp
15 Mar 2023, 01:29 ( Updated at: 15 Mar 2023, 01:44 )

Still getting error

Hi,

I am still getting the error. I am sharing the source code. Could you please try this on your end? It got 2 params, EventHours and  EventMins. If an economic event in an econimic calender is AT 16:30, The hours param will be 16 and the mins will be 30. Basically I am trying to execute an order at the same time market data in the economic calender is released. You can look at follwong calender for economic events

 

 

 

Source code

###########

 

using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Threading;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.TasmaniaStandardTime, AccessRights = AccessRights.FullAccess)]
    public class test00 : Robot
    { 
    
        public bool showMessage = true;


        #region Input Parameters


        [Parameter("Event Hours (24HR format)", Group = "WebSite")]
        public int EventHours { get; set; }
        [Parameter("Event Mins", Group = "WebSite")]
        public int EventMins { get; set; } 


        #endregion


        protected override void OnStart()
        {

            var economicEventTime = DateTime.Now.Date.AddHours(EventHours).AddMinutes(EventMins);
            ShowMessage("Now : " + DateTime.Now.ToString());
            ShowMessage(economicEventTime.ToString());

            if (DateTime.Now < economicEventTime)
                Thread.Sleep((int)economicEventTime.Subtract(DateTime.Now).TotalMilliseconds); 


            var ExecutResult = ExecuteMarketOrder(TradeType.Sell, "AUDUSD", 5000, Guid.NewGuid().ToString(), null, 20); 
        }


        protected override void OnException(Exception exception)
        {
            ShowMessage("OnException: " + exception.Message);

            if ((exception.InnerException != null))
                ShowMessage("OnException Inner: " + exception.InnerException.Message);
            Environment.Exit(0);

        }
        protected override void OnError(Error error)
        {

            ShowMessage("Error :" + error.ToString());

            ShowMessage("Error Code:" + error.Code.ToString());
            Environment.Exit(0);
        }

        private void ShowMessage(string message)
        {
            if (showMessage)
                Print(message);
        }
    }

}
 

 

 


@prasanthtp

Spotware
15 Mar 2023, 08:30

Hi prasanthtp,

As pointed out in our previous post, we need to arrange a TeamViewer session to investigate this on your pc.

Best Regards,

cTrader Team


@Spotware

Spotware
20 Mar 2023, 11:09

Hi prasanthtp,

Our team has investigated your issue and here are our suggestions

  1. Don't use Thread.Sleep(). Use Timer instead of it.
  2. Don't use Environment.Exit(0) - it kills the cBot process. Use the Stop() function.

Find a code example below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Threading;

namespace cAlgo.Robots
{
    /*
    1) Don't use Thread.Sleep(). Use Timer instead of it
    2) Don't use Environment.Exit(0) - it kills cBot process. Use the `Stop()` function.
    */
    [Robot(AccessRights = AccessRights.None)]
    public class issue_40281 : Robot
    {
        [Parameter("Event Hours (24HR format)", Group = "WebSite")]
        public int EventHours { get; set; }
        [Parameter("Event Mins", Group = "WebSite")]
        public int EventMins { get; set; }

        public bool showMessage = true;

        protected override void OnStart()
        {
            var economicEventTime = DateTime.Now.Date.AddHours(EventHours).AddMinutes(EventMins);
            ShowMessage("Current Local Time : " + DateTime.Now.ToString());
            ShowMessage("Economic news Local Time : " + economicEventTime.ToString());


            /*
            you can also use event `TimerTick` to handle it in custom event handler instead of embedded OnTimer callback.
            
            Timer.TimerTick += OnTimerTick;

            private void OnTimerTick()
            {
            }
            */

            if (DateTime.Now < economicEventTime)
                Timer.Start((int)economicEventTime.Subtract(DateTime.Now).TotalSeconds);
        }


        protected override void OnTimer()
        {
            Print("OnTimer");
            Timer.Stop();
            var ExecutResult = ExecuteMarketOrder(TradeType.Sell, "AUDUSD", 5000, Guid.NewGuid().ToString(), null, 20);
        }


        protected override void OnException(Exception exception)
        {
            ShowMessage("OnException: " + exception.Message);

            if ((exception.InnerException != null))
                ShowMessage("OnException Inner: " + exception.InnerException.Message);
            Stop();

        }
        protected override void OnError(Error error)
        {

            ShowMessage("Error :" + error.ToString());

            ShowMessage("Error Code:" + error.Code.ToString());
            Stop();
        }

        private void ShowMessage(string message)
        {
            if (showMessage)
                Print(message);
        }
    }
}

Best Regards,

cTrader Team


@Spotware