[BUG] CBot dont put SL on every order

Created at 01 Apr 2019, 22:48
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!
MR

mr.jhonnysabino

Joined 01.04.2019

[BUG] CBot dont put SL on every order
01 Apr 2019, 22:48


 

Hello, apparently all the bots I am building are presenting this bug at least during the backtest, if I continue then I will not have the courage to put the bot to work in real account and unfortunately I will have to give up the platform.

I do not know exactly what makes the bug happen, but if you test it for example from 01/01/2019 until today, you will see that in some orders the stop loss is inserted and others are not, which causes the order is only closed several days later when it reaches the TP, the drawdown is huge.

I'll put my code here, there seems to be nothing wrong with programming.

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 BotTest : Robot
    {

        [Parameter("** Bot **", DefaultValue = "")]
        public string cbotName { get; set; }

        [Parameter("Money Management", DefaultValue = false)]
        public bool moneyManagement { get; set; }

        [Parameter("Risk Percent", DefaultValue = 2)]
        public double riskPercent { get; set; }

        [Parameter("Lot Size", DefaultValue = 0.01)]
        public double lotSize { get; set; }

        [Parameter("Stop Loss", DefaultValue = 10)]
        public double stopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 10)]
        public double takeProfit { get; set; }


        protected override void OnTick()
        {
            Strategy();
        }

        private void Strategy()
        {

            double buyers = Math.Round(MarketSeries.Close.Last(1) - MarketSeries.Low.Last(1), 5);
            double sellers = Math.Round(MarketSeries.High.Last(1) - MarketSeries.Close.Last(1), 5);

            bool Buy_Condition_1 = buyers > sellers;
            bool Sell_Condition_1 = sellers > buyers;

            if (Buy_Condition_1)
            {
                if (Positions.Count == 1)
                {
                    return;
                }
                if (!moneyManagement)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.LotSize * lotSize, "Bot", stopLoss, takeProfit);
                }
                else
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, MoneyManagement() * Symbol.LotSize, "Bot", stopLoss, takeProfit);
                }
            }
            if (Sell_Condition_1)
            {
                if (Positions.Count == 1)
                {
                    return;
                }
                if (!moneyManagement)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.LotSize * lotSize, "Bot", stopLoss, takeProfit);
                }
                else
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, MoneyManagement() * Symbol.LotSize, "Bot", stopLoss, takeProfit);
                }


            }


        }

        private double MoneyManagement()
        {
            double balance = Account.Balance;
            double riskMoney = (balance / 100) * riskPercent;
            double riskPercentLot = (riskMoney / stopLoss);

            return Math.Round(riskPercentLot, 2);
        }

    }
}

@mr.jhonnysabino
Replies

PanagiotisCharalampous
02 Apr 2019, 12:11

Dear mr.jhonnysabino,

Thanks for posting in our forum. Can you please provide us with the following so that we can check

  1. cBot parameters
  2. Backtesting parameters
  3. Broker

Best Regards,

Panagiotis


@PanagiotisCharalampous

mr.jhonnysabino
02 Apr 2019, 18:24 ( Updated at: 21 Dec 2023, 09:21 )

Thank you for help Panagiotis.

cBot parameters

The bug occurs in any parameter.

Try to use tick chart or timeframes and the result will be the same, it happens with any stop loss level also, take profit works normally.

Backtesting parameters

Broker

IC Markets

 


@mr.jhonnysabino