Backtesting for hedged accounts

Created at 27 Mar 2014, 23:23
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!
AlexanderRC's avatar

AlexanderRC

Joined 04.02.2014

Backtesting for hedged accounts
27 Mar 2014, 23:23


Hello.

Are there a way to backtest the robot which assumes that it can open several individual positions for the symbol?

In cBroker, the account has the type of "Hedging".

When I try to backtest such a robot, backtesting engine just merges opened positions into one.


@AlexanderRC
Replies

Spotware
28 Mar 2014, 10:14

There is no netting functionality in backtesting. Probably you have a mistake in code of your cBot.

Try to backtest the following cBot and you will see that positions are not merged:

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000);
            ExecuteMarketOrder(TradeType.Sell, Symbol, 10000);
        }

        protected override void OnStop()
        {
            foreach (var p in Positions)
                ClosePosition(p);
        }
    }
}

 


@Spotware

AlexanderRC
01 Apr 2014, 04:25

RE:

That code works as intended. I even modified it to open 3 distinct Buy orders in 3 consequtive OnBar() invocations. The positions are distinct both for netted and hedged demo accounts.

The problem with me thinking that position was merged was that the line for long running position was above or below on the backtesting chart. When I clicked on the Graph tab, i only saw one the line for one position (instead of several lines for several positions) because the local chart quotes around the clicked position did not cross the lines of other positions which were hidden as they were off chart due radically different open and close prices.


@AlexanderRC