StopLoss not honoured/executed

Created at 25 Feb 2020, 12:16
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!
SH

Shares4UsDevelopment

Joined 14.10.2018

StopLoss not honoured/executed
25 Feb 2020, 12:16


My Stop loss did not execute

I understand that when you execute an order, and whilst filling it the  spread gets so wide that the stoploss is in the spread, the order would close in a loss immediately.

But what I see is that the Stoploss is not set at all and the position runs wild!

Expected behavior:

1. Check spread and do not place the position if its too wide but return a 'StopLoss in spread error' (= BEST OPTION);
2. If that's not possible Close the position immediately after the attempt to set the SL;
3. If that's not possible Adjust the stoploss a little over the spread.

But please CTDN,

Please ensure to NEVER leave a position that is supposed to be protected WITHOUT PROTECTION.

Here is a small debug print of the encountered ( but in-time discovered ) disaster

25/02/2019 23:00:02.241 | debug Open Buy XAUUSD vol:5 SLPips:21
25/02/2019 23:00:02.241 | debug Opened Buy 2 Result(pips):-18 SL:1327.47
25/02/2019 23:00:03.118 | debug Closed Buy 2 Result(pips):-23 SL:1327.47

25/02/2019 23:00:39.001 | debug Open Buy XAUUSD vol:5 SLPips:21
25/02/2019 23:00:39.001 | debug Opened Buy 3 Result(pips):-18 SL:1327.5
25/02/2019 23:00:40.873 | debug Closed Buy 3 Result(pips):-21 SL:1327.5

25/02/2019 23:00:40.873 | debug Open Buy XAUUSD vol:5 SLPips:21
25/02/2019 23:00:40.873 | debug Opened Buy 4 Result(pips):-18 SL:1327.47
25/02/2019 23:00:41.176 | debug Closed Buy 4 Result(pips):-26 SL:1327.47

25/02/2019 23:00:49.845 | debug Open Buy XAUUSD vol:5 SLPips:21
25/02/2019 23:00:49.845 | debug Opened Buy 5 Result(pips):-35 SL:null
26/02/2019 00:07:01.210 | debug Closed Buy 5 Result(pips):-61 SL:null


 

 


@Shares4UsDevelopment
Replies

PanagiotisCharalampous
25 Feb 2020, 12:22

Hi A.R. 

This is by design. Stop losses are set only after a position is opened but it is not possible to be set within the spread. It is the responsibility of the cBot developer to check if the stop loss has been succesfuly set and handle the situation if otherwise.

Best Regards,

Panagiotis 

Join us on Telegram


 


@PanagiotisCharalampous

Shares4UsDevelopment
26 Feb 2020, 07:59

RE:

Dear Panagiotis

There we differ.
I think that if a program tells your system to execute something it should either do it or give an error
message or,  when it is a multi step execution, try to rollback and give an error message, or fix the damage
in the best possible way and notify the principal/client/

It is the responsibility of the contractor/receiver to execute or to say it can't.

That's the way 99.9% of all the things work in programming.

I've done some forum research here but this is an issue that already exists for a longer period.

Would be nice if you guys could solve it.

Otherwise a connection failure, power outage or computer restart might leave a cTrader user unprotected.
And that's not what we want , do we?

Best rgds,
A.R.


@Shares4UsDevelopment

PanagiotisCharalampous
26 Feb 2020, 09:27

Hi A.R. 

The API offers you the tools to check this. See below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Positions.Opened += Positions_Opened;
            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000, "", 0.1, null);
        }

        private void Positions_Opened(PositionOpenedEventArgs obj)
        {
            if (obj.Position.StopLoss == null)
            {
                // Handle the scenario where a stop loss was not set.
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

As per your comment 

It is the responsibility of the contractor/receiver to execute or to say it can't.

We report to you that the Stop Loss has not been set. Any further decisions are trading decisions and it is not the job of the API to take trading decisions on behalf of the trader. This task should be a responsibility of the strategy/cBot. After all the cBot is a "contractor" itself. 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4UsDevelopment
26 Feb 2020, 09:42

RE:

 

We report to you that the Stop Loss has not been set. Any further decisions are trading decisions and it is not the job of the API to take trading decisions on behalf of the trader. This task should be a responsibility of the strategy/cBot. After all the cBot is a "contractor" itself. 

 

As I said: We differ!
I know I can check and have to act accordingly,
But you're missing the point.
You are NOT notifying the client. The client has to check if you did your job 100%.
Throwing an errormessage would be notifying.
And furthermore: Only doing half the job without notifying is i.m.o. bad service.

Best rgds,

A.R.
 

 


@Shares4UsDevelopment

firemyst
05 Mar 2020, 02:44 ( Updated at: 21 Dec 2023, 09:21 )

@Panagiotis / @A.R.,

I think where the issue is here is the functionality differences between the "client" and the "bot".

For example, when placing a trade in the client, with a stoploss smaller than the current spread, we receive the following error notification:

The order is still placed and position still opened - it's just there's no SL set.

When doing something similar in a cBot, what @A.R. is saying is that they would expect some sort of similar notification/exception stating there's a known issue.

However, as @Panagiotis says, you have to ensure yourself by checking the SL after opening the position.

 

@A.R., a trader's argument might be is the trader might still want the position opened because they got in at a great price. In the client, if this happened, the trader would just modify the order to input a correct SL without closing and reopening the position (to avoid commission costs for example). Also, who's to determine what "a little over the spread" is? Suppose I wanted the SL at 1, but accidentally put in 0.1, and the spread is 0.25? Are you going to make my SL 0.3 now when I really wanted 1?

So your suggestions #2 & #3 above just aren't practical or feasible.

For your suggestion #1 @A.R., what's the difference between checking if the SL is null vs checking to see if an exception is thrown? You still have to perform a check and do something either way.

However, in the .Net framework, checking if the SL is null is significantly faster in terms of performance than using any sort of try/catch block. And with trading, speed is of the essence

.


@firemyst