When backtesting FreeMargin is ignored

Created at 12 Oct 2018, 17:00
TH

Thomas.Henrich

Joined 11.10.2018

When backtesting FreeMargin is ignored
12 Oct 2018, 17:00


When a bot does a ExecuteMarketOrder and i dont have enough FreeMargin i get an error for insufficient fund, however when backtesting my FreeMargin is ignored and the bot can just keep placing orders as long as my equity doesn't fall below 0.

Heres a simple bot to demonstrate the problem.

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 test : Robot
    {
        [Parameter("Lots", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Lots { get; set; }

        public int OrderCounter = 0;

        protected override void OnStart()
        {
        }

        protected override void OnBar()
        {
        }

        protected override void OnTick()
        {
            OrderCounter++;
            ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.QuantityToVolumeInUnits(Lots), "test", 0, 0);
            Print("{0}: FreeMargin =  {1}   Equity =  {2}   Balance =  {3}   Leverage = {4}    Lots =  {5}", OrderCounter, Account.FreeMargin, Account.Equity, Account.Balance, Account.PreciseLeverage, Lots);
        }

        protected override void OnStop()
        {
            Print("FreeMargin =  {0}   Equity =  {1}   Balance =  {2}    Leverage = {3}   Lots =  {4}", Account.FreeMargin, Account.Equity, Account.Balance, Account.PreciseLeverage, Lots);
        }
    }
}

 


@Thomas.Henrich
Replies

PanagiotisCharalampous
12 Oct 2018, 17:47

Hi Thomas,

Thanks for posting in our forum. At the moment, backtesting does not take into account free margin. This feature will be added in a future release.

Best Regards,

Panagiotis


@PanagiotisCharalampous