Bug in Backtesting

Created at 13 Sep 2015, 02:05
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!
moneybiz's avatar

moneybiz

Joined 06.12.2011

Bug in Backtesting
13 Sep 2015, 02:05


Please look at the trade #540.
The position closes at a price which has never been reached. This means that all of the backtestings we make are meaningless.
We are testing on ghost data.

 


@moneybiz
Replies

moneybiz
13 Sep 2015, 02:09

Also the bug is valid for optimization. I first optimized then backtested few times to see if the error is temporary but it's there all the time and on different computers.


@moneybiz

moneybiz
13 Sep 2015, 02:14 ( Updated at: 21 Dec 2023, 09:20 )

Here is the balance-equity curve.


@moneybiz

moneybiz
13 Sep 2015, 02:20 ( Updated at: 21 Dec 2023, 09:20 )


@moneybiz

tradermatrix
13 Sep 2015, 19:38 ( Updated at: 23 Jan 2024, 13:16 )

Hello
I already asked this question..et the answer here:

[/forum/calgo-support/6054]


cordially


@tradermatrix

moneybiz
13 Sep 2015, 19:50 ( Updated at: 23 Jan 2024, 13:16 )

RE:

tradermatrix said:

Hello
I already asked this question..et the answer here:

[/forum/calgo-support/6054]


cordially

It has been about 2 months and there is no solution yet.
If you look at the chart above it is not a tick data problem. It's internal bug in backtest engine.
If it was a tick data problem the bar would look different since I believe the bar is constructed from tick data itself.

There is probably some approximation error which calculates the tick data to be at different price.


@moneybiz

Spotware
14 Sep 2015, 09:31

Dear Trader,

Could you please clear your backtesting cache and try again?

You backtesting cache is located in:

C:\Users\%USERNAME%\AppData\Roaming\%BROKER%-cAlgo\BacktestingCache

 


@Spotware

tradermatrix
14 Sep 2015, 11:21

RE:

Spotware said:

Dear Trader,

Could you please clear your backtesting cache and try again?

You backtesting cache is located in:

C:\Users\%USERNAME%\AppData\Roaming\%BROKER%-cAlgo\BacktestingCache

 

I have applied this method but the problem remains the same


@tradermatrix

Spotware
14 Sep 2015, 11:34

Dear Trader,

Could you please send us your brokers name and the environment you use (live or demo) at troubleshooting@spotware.com


@Spotware

moneybiz
14 Sep 2015, 12:49

RE:

Spotware said:

Dear Trader,

Could you please send us your brokers name and the environment you use (live or demo) at troubleshooting@spotware.com

It's backtesting should not be depended on live or demo account.

Anyway, I sent an email to the above address.


@moneybiz

tradermatrix
14 Sep 2015, 12:53

RE:

Spotware said:

Dear Trader,

Could you please send us your brokers name and the environment you use (live or demo) at troubleshooting@spotware.com

the problem is the same in all my brokers:

fxpro.....ic market....pepperstone...roboforex.....and also in demo mode ... spotware c algo !

exemple

take such sample martingale cbot ..
from the June 1st, 2015
there is a crash or a rise ... of very many orders in the same minute.
(Backtesting tick data ....)

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleMartingalecBot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 20)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 20)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, GetRandomTradeType());
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

thank you to look this problem
Best regards


@tradermatrix

Spotware
28 Sep 2015, 15:39 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Dear Trader,

As you probably already know:

Sell positions open on bid prices and close on ask prices.

Buy positions open on ask prices and close on bid prices.

The bid and ask prices are defined by the Liquidity Providers. Usually the ask price is higher than the bid price. Sometimes the ask price may become lower than the bid price based on the liquidity provided by the LPs. As you most probably already know the charts are drawn based only on the bid prices. In cases where a position is opened or closed based on the ask price the endpoints of dealing lines could be above the candle or in some rare cases below the candle.

An excellent example of a rare case is the post of the trader moneybiz whose robot closed a sell position at the exact time where the ask price was lower than the bid price.

moneybiz said:

Please look at the trade #540.
The position closes at a price which has never been reached. This means that all of the backtestings we make are meaningless.
We are testing on ghost data.

 

 


@Spotware