Entity Not Found

Created at 26 Apr 2019, 04:45
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!
lec0456's avatar

lec0456

Joined 14.11.2012

Entity Not Found
26 Apr 2019, 04:45


Hi I am getting a strange error. My Bot modifies the stop loss and then the position closes when hitting the SL.  But the server is returning a message "EntityNotFound". After that I have some code in the OnClose event that prints some stuff to the console. What could be the reason for this?

 

26/04/2019 04:30:49.263 | Master cBot V2.11, EURUSD, m15 | TKSess SL BE
26/04/2019 04:30:49.278 | Master cBot V2.11, EURUSD, m15 | Modifying position PID2914450 (SL: 1.11342, TP: 1.11442)
26/04/2019 04:30:49.763 | Master cBot V2.11, EURUSD, m15 | → Modifying position PID2914450 (SL: 1.11342, TP: 1.11442) SUCCEEDED, Position PID2914450
26/04/2019 04:35:40.153 | Master cBot V2.11, EURUSD, m15 | Closing position PID2914450
26/04/2019 04:35:40.825 | Master cBot V2.11, EURUSD, m15 | → Closing position PID2914450 FAILED with error "EntityNotFound", Position PID2914450
26/04/2019 04:35:40.872 | Master cBot V2.11, EURUSD, m15 | ErrorCode: Entity Not Found.
26/04/2019 04:35:41.341 | Master cBot V2.11, EURUSD, m15 | Last Position Closing...
26/04/2019 04:35:41.341 | Master cBot V2.11, EURUSD, m15 | Closed: TKSess:100 @ 04/26/2019 04:35:41.341 ClgPips: 0 DlyPips: -0.1 AvDlyPips: 0
26/04/2019 04:35:41.341 | Master cBot V2.11, EURUSD, m15 | MxPips: 4.2 Pft: -1.24 TradeStart: 815 Pos Cnt: 0 UpTrd: False DnTrd: True
26/04/2019 04:35:41.341 | Master cBot V2.11, EURUSD, m15 | ssum96_0: -0.61 MaxPosDD: 0.53 cls-ma1pk: 1.70

 


@lec0456
Replies

DonaldD
26 Apr 2019, 11:44

This usually happens when you are trying to close a position that does not exist. Sharing the cBot code might shed some light to this.


@DonaldD

lec0456
26 Apr 2019, 13:51

Well, is there a way to test if the position exists before closing it?


@lec0456

PanagiotisCharalampous
30 Apr 2019, 12:45

Hi lec0456,

You can check the Poistions collection but I can assume you already do that. Donald is right, sharing the cBot code might help understanding the causes and giving more appropriate guidance.

Best Regards,

Panagiotis


@PanagiotisCharalampous

lec0456
03 Jun 2019, 20:00

In the OnTick Event I have the following code:

                #region Manual Stoploss Position Closing for good measure only
                foreach (var position in Positions)
                {
                    if (position!=null && position.TradeType==TradeType.Buy && position.StopLoss!=null && Symbol.Bid<position.StopLoss)
                    {
                        Log(paramIntLogEnable, paramExtLogEnable,"Sending Manuel SL Sell Close of {0} @tick {1}", position.Label,t0);
                        if (ClosePosition(position).IsSuccessful && Positions.Count == 0) return;
                    }
                    
                    if (position!=null && position.TradeType==TradeType.Sell && position.StopLoss!=null && Symbol.Ask>position.StopLoss)
                    {
                        Log(paramIntLogEnable, paramExtLogEnable,"Sending Manuel SL Sell Close of {0} @tick {1}", position.Label,t0);
                        if (ClosePosition(position).IsSuccessful && Positions.Count == 0) return;
                    }
                }
                #endregion

Frankly the code should never run because when the position hits the stoploss it should close but it does run when there is a jump in price.

 

Here is an exapmple of what it did today while live trading:

03/06/2019 17:00:18.342 | Master cBot V2.11, EURUSD, m15 | Sending Manuel SL Close of NYSess:100
03/06/2019 17:00:18.342 | Master cBot V2.11, EURUSD, m15 | Closing position PID2965992
03/06/2019 17:00:18.545 | Master cBot V2.11, EURUSD, m15 | → Closing position PID2965992 FAILED with error "TechnicalError", Position PID2965992
03/06/2019 17:00:18.561 | Master cBot V2.11, EURUSD, m15 | ErrorCode: Technical Error #1.
03/06/2019 17:00:18.561 | Master cBot V2.11, EURUSD, m15 | Sending Manuel SL Close of NYSess:100
03/06/2019 17:00:18.561 | Master cBot V2.11, EURUSD, m15 | Closing position PID2965992
03/06/2019 17:00:18.733 | Master cBot V2.11, EURUSD, m15 | → Closing position PID2965992 FAILED with error "EntityNotFound", Position PID2965992
03/06/2019 17:00:18.733 | Master cBot V2.11, EURUSD, m15 | ErrorCode: Entity Not Found.

 


@lec0456