Major bug in cTrader automate back-testing.

Created at 13 Apr 2019, 18:20
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!
FI

firemyst

Joined 26.03.2019

Major bug in cTrader automate back-testing.
13 Apr 2019, 18:20


Hey everyone:

This looks like a major bug to me, which will at least affect people's back-testing results, so needs to be fixed ASAP for people to have any sort of confidence in cTrader's back-testing.

See two attached images. 

Sell order entry prices are around the 1.13 mark; stop losses are hit around the 0.90 mark. These orders happen every second.

Notice the EURUSD price range, but cTrader is reporting multiple net profits as it's obviously confused by modifying the stop-loss to setting it below the current ask/bid price on sell/short orders. 

Back-tested this code, with different dates, against both live and demo accounts on IC Markets and Pepperstone, so it can't possibly be bad tick data.

There's no way a sell order entry at 1.13 happens every second, exiting with at a stop loss at 0.90 with huge profits, when everyone can clearly see from the candles the price never drops below 1.10.

This is a major bug and needs to be fixed ASAP. Otherwise, nobody will be able to trust back-testing results in cTrader.

 


@firemyst
Replies

PanagiotisCharalampous
14 Apr 2019, 18:45

Hi FireMyst,

Can you please share with us the cBot code so that we can reproduce these results?

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
15 Apr 2019, 03:05

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Can you please share with us the cBot code so that we can reproduce these results?

Best Regards,

Panagiotis

No worries. I didn't know if you wanted it public or sent privately. Anyway, here you go. Set the timeframe to H1 (1 hour). I just tried again with EURUSD and AUDJPY pairs on both PepperStone and IC Markets for March 7-8, 2019 with similar results:

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 TestBot : Robot
    {
        [Parameter(DefaultValue = 1000)]
        public int PositionSize { get; set; }

        private string _positionLabel = String.Empty;
        private double _stopLossInPips = 50;
        private double _runningTotalGainLoss = 0;
        private readonly double StopBotWhenLossesFallBelow = -1000;

        protected override void OnStart()
        {
            _positionLabel = (MarketSeries.TimeFrame) + " " + Symbol.Code + " Test Bot";
            Positions.Closed += Positions_Closed;
            Positions.Opened += Positions_Opened;
        }

        private void Positions_Closed(PositionClosedEventArgs args)
        {
            Position p = args.Position;
            _runningTotalGainLoss += p.NetProfit;
            if (_runningTotalGainLoss < StopBotWhenLossesFallBelow)
            {
                Print("WARNING! Running total {0} has fallen below StopBotWhenLossesFallBelow {1} threshold! Stopping bot for {2}!", String.Format("{0:$#,###.00}", _runningTotalGainLoss), String.Format("{0:$#,###.00}", StopBotWhenLossesFallBelow), _positionLabel);
                Stop();
                return;
            }
        }

        private void Positions_Opened(PositionOpenedEventArgs args)
        {
            Position p = args.Position;
            double stopLossMultiplier = 0.8;
            TradeResult r = p.ModifyStopLossPrice(p.EntryPrice * stopLossMultiplier);
        }

        protected override void OnTick()
        {
            // Put your core logic here
            if (Positions.Count == 0)
            {
                string commentString = _positionLabel + "; Short Buy; " + String.Format("{0:#,###}", PositionSize) + "; TSL in Pips:" + String.Format("{0:#,###.00000}", _stopLossInPips) + "; Approx Time:" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss");
                Print("{0}", commentString);
                TradeResult r = ExecuteMarketOrder(TradeType.Sell, Symbol, PositionSize, _positionLabel, _stopLossInPips, null, null, "blah", true);
            }
        }
    }
}

 


@firemyst

PanagiotisCharalampous
16 Apr 2019, 16:10

Hi FireMyst,

Thanks, our team is looking into it.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
16 Apr 2019, 16:28

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Thanks, our team is looking into it.

Best Regards,

Panagiotis

Awesome.

 

Keep us posted please.

 

Thank you @Panagiotis.


@firemyst

firemyst
26 Apr 2019, 18:13

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Thanks, our team is looking into it.

Best Regards,

Panagiotis

@Panagiotis:

Any updates on this?

Thank you


@firemyst

PanagiotisCharalampous
30 Apr 2019, 12:49

Hi FireMyst,

It is planned to be fixed in 3.5.

Best Regards,

Panagiotis


@PanagiotisCharalampous