cTrader doesn't set SL bug

Created at 19 Dec 2023, 18:51
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!
IN

Intetics

Joined 29.11.2023

cTrader doesn't set SL bug
19 Dec 2023, 18:51


It looks like cTrader doesn't set stop losses as requested if the stop loss is smaller than the spread.

Steps to reproduce:

Add a new bot with the following code:

using cAlgo.API;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.FullAccess)]
    public class NullSLBug : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
            Print(Message);
        }

        protected override void OnBar()
        {
            if (Time == new DateTime(2023, 08, 09, 9, 31, 0))
            {
                //Debugger.Launch();
                double qty = 100;
                double slInPips = 1;
                Print($"SL in Pips: {slInPips}");
                var trade = ExecuteMarketOrder(TradeType.Buy, SymbolName, qty, "MyBot", slInPips, 0.1, "Test", false);
                Print($"Actual SL: {trade.Position.StopLoss}");
            }
        }
    }
}

Select:

  • Invitae_(NVTA.N) as a financial instrument for the bot
  • 1m time frame
  • start date of the backtesting = 08/08/2023
  • backtesting spread = 1.1

Run the backtest. You'll see that the trade.Position.StopLoss is null.

However, if you change the spread to 0.9 then cTrader will correctly set the Stop Loss.

Additional data:

  • Broker: PepperStone
  • Account Type: Test
  • Account Balance: 10,000

 


@Intetics
Replies

PanagiotisCharalampous
20 Dec 2023, 06:39

Hi there,

This is not a bug, it's by design. You should check for these cases in your code and act accordingly.

Best regards,

Panagiotis


@PanagiotisCharalampous

Intetics
20 Dec 2023, 06:42

RE: cTrader doesn't set SL bug

PanagiotisCharalampous said: 

Hi there,

This is not a bug, it's by design. You should check for these cases in your code and act accordingly.

Best regards,

Panagiotis

Hi Panagiotis,

How come not setting a stop loss can be by design? Shouldn't the ExecuteMarketOrder return IsSuccessful = false if the code can't place the trade I want?

Regards


@Intetics