Robot stops at 'EntityNotFound' error

Created at 23 Nov 2017, 12:08
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!
AN

Anka Software

Joined 06.11.2014

Robot stops at 'EntityNotFound' error
23 Nov 2017, 12:08


Hi,

    Due to 'inflight errors' , my robot runs into 'EntityNotFound' error, when trying to modify SL of a position, which is already closed at exchange, but still exits in the Positions collection in the cAlgo terminal. 

   This error is causing the robot to stop.

   How to catch this error, and keep the robot running. Please advise.

Regards

Vivek


@Anka Software
Replies

PanagiotisCharalampous
23 Nov 2017, 12:18

Hi Anka Software,

The best way to handle exceptions in C# is apply proper exception handling. You can read more about exception handling here or here. Let me know if this helps you.

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

Anka Software
23 Nov 2017, 12:59

RE:

Panagiotis Charalampous said:

Hi Anka Software,

The best way to handle exceptions in C# is apply proper exception handling. You can read more about exception handling here or here. Let me know if this helps you.

Best Regards,

Panagiotis

 

Dear Panagiotis,

     Thanks, for your response. So a simple C# try / catch block will keep the robot running on 'EntityNotFound' error??


@Anka Software

PanagiotisCharalampous
23 Nov 2017, 13:03

Hi Anka Software,

It should but if you want you can share some code and maybe I can propose a better approach.

Best Regards,

Panagiotis


@PanagiotisCharalampous

Anka Software
23 Nov 2017, 13:06

Dear Panagiotis,

     Code enclosed

 TradeResult result = null;
                    try
                    {
                        result = ModifyPosition(position, newSL, newProfit);
                    }
                    catch(Exception e)
                    {
                        Print("Could not modify position, due to " + result.Error.ToString() + ", " + e.StackTrace);
                    }

 

 

Regards

 

Vivek


@Anka Software

PanagiotisCharalampous
23 Nov 2017, 14:54

Hi Vivek,

I would propose that you get the position just before using it, instead of keeping it memory. See below

            var position = Positions.Find("Some Label");
            if (position != null)
              result = ModifyPosition(position, newSL, newProfit);

Is this feasible based on your cBot's logic?

Best Regards,

Panagiotis


@PanagiotisCharalampous