Question about back-testing bots that have a random trade element.

Created at 15 Mar 2016, 14:01
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!
ST

stevie.c

Joined 28.09.2015

Question about back-testing bots that have a random trade element.
15 Mar 2016, 14:01


Hi all,

I have been experimenting with bots while I become familiar with their development, and one thing I have noticed when trialling some of the downloadable bots is that any bot that uses a random trade element (e.g. typically a Martingale bot) always seems to back-test with the same results. How can this be if the trades are meant to be random?

Surely, if nothing is changed on a back-test for one of these bots (i.e. all parameters are constant for each back-test), then the back-test results should vary depending on the random trades being performed by the bot? It seems, however, that the results are the same every single time. Am I doing something wrong? Is there some setting I should be using?

Thanks.

 


@stevie.c
Replies

Spotware
17 Mar 2016, 15:35

Dear Trader,

If you use the Sample Martingale cBot, without changing the initial source code the backtesting results should be slightly different. However, if you check the code you will notice that only the direction of the opening position is random. It is possible that many backtesting results could be almost identical if you use the same historical data.


@Spotware

stevie.c
17 Mar 2016, 20:09

RE:

Thanks Spotware. When you say that only the direction of the opening position is random, do you mean to imply that only the direction of the very first opening position is random, and that no others are? Doesn't the following ensure that any new trade is random..?

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

Thanks.


@stevie.c

whis.gg
17 Mar 2016, 23:53

Hello, if you want to execute random order each time, change following piece of code:

if (position.GrossProfit > 0)                                 // if last closed position ended up in profit
{
   ExecuteOrder(InitialQuantity, GetRandomTradeType());       // execute random trade type order
}
else                                                          // else
{
   ExecuteOrder(position.Quantity * 2, position.TradeType);   // execute same trade type order as last one with doubled quantity
}

to this:

if (position.GrossProfit > 0)                                 // if last closed position ended up in profit
{
   ExecuteOrder(InitialQuantity, GetRandomTradeType());       // execute random trade type order
}
else                                                          // else
{
   ExecuteOrder(position.Quantity * 2, GetRandomTradeType()); // execute random trade type order with doubled quantity
}

 

I hope it helps. :)


@whis.gg

stevie.c
24 Mar 2016, 02:41

RE:

Thanks TMC. The randomness when the last closed position ended up in profit just didn't seem random enough during backtesting. Perhaps it is an artefact of this type of trading strategy.

Cheers.


@stevie.c