Backtesting Performance issue

Created at 30 Jul 2022, 18:37
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!
80

8034130

Joined 24.01.2014

Backtesting Performance issue
30 Jul 2022, 18:37


Hello,

For the 4.2 release we have a very big performance problem. 
You can choose any symbol and timeframe 4 hours.
The properties for backtesting are as follows:

  • m1 bars from server

The code below requires more than one day for a period of 1 month (e.g. 01.01.2022 - 01.02.2022) for backtesting!

Can you please solve this issue ?

Best regards

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class TestPerformance : Robot
    {

        [Parameter("Quantity (Lots)", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private readonly List<string> mSymbolFrom = new List<string>();
        public Dictionary<string, Bars> mBars = new Dictionary<string, Bars>();

        private int mPos = 0;
        private string mLabel = "TestPerformance";
        private int mInitVolume = 1;

        protected override void OnStart()
        {
            mSymbolFrom.Add("EURJPY");
            mSymbolFrom.Add("EURGBP");
            mSymbolFrom.Add("EURCAD");
            mSymbolFrom.Add("EURAUD");
            mSymbolFrom.Add("EURCHF");
            mSymbolFrom.Add("EURUSD");
            mSymbolFrom.Add("EURNZD");

            mSymbolFrom.Add("AUDCAD");
            mSymbolFrom.Add("AUDCHF");
            mSymbolFrom.Add("AUDJPY");
            mSymbolFrom.Add("AUDUSD");
            mSymbolFrom.Add("AUDNZD");

            mSymbolFrom.Add("NZDCAD");
            mSymbolFrom.Add("NZDCHF");
            mSymbolFrom.Add("NZDJPY");
            mSymbolFrom.Add("NZDUSD");

            mSymbolFrom.Add("GBPCAD");
            mSymbolFrom.Add("GBPCHF");
            mSymbolFrom.Add("GBPUSD");
            mSymbolFrom.Add("GBPJPY");
            mSymbolFrom.Add("GBPAUD");
            mSymbolFrom.Add("GBPNZD");

            mSymbolFrom.Add("USDJPY");
            mSymbolFrom.Add("USDCAD");
            mSymbolFrom.Add("USDCHF");

            mSymbolFrom.Add("CADCHF");
            mSymbolFrom.Add("CADJPY");
            mSymbolFrom.Add("CHFJPY");

            foreach (string lSymbol in mSymbolFrom)
            {

                //Hist.Add(lSymbol + lTimeFrame, CreateDataSeries());
                //Result.Add(lSymbol + lTimeFrame, CreateDataSeries());

                Bars lBars = MarketData.GetBars(TimeFrame, lSymbol);
                lBars.BarOpened += Bars_BarOpened;
                mBars.Add(lSymbol, lBars);
                //GetPastNew(lBars, lTimeFrame, lSymbol, true, 5, 0.1);
                //foreach (var lTimeFrame in mTimeFrames)
                //{

                //}
            }
        }

        private void DeletePendingOrderShort(string aSymbol)
        {
            foreach (var order in PendingOrders.Where(aX => aX.TradeType.Equals(TradeType.Sell)))
            {
                if (order.SymbolName.Equals(aSymbol) && order.Label.Contains(mLabel))
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private void DeletePendingOrderLong(string aSymbol)
        {
            foreach (var order in PendingOrders.Where(aX => aX.TradeType.Equals(TradeType.Buy)))
            {
                if (order.SymbolName.Equals(aSymbol) && order.Label.Contains(mLabel))
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            if (IsBacktesting)
            {
                Chart.RemoveAllObjects();
            }
            //var lTimeFrame = obj.Bars.TimeFrame;
            var lSymbol = obj.Bars.SymbolName;

            var lCurrentSymbol = Symbols.GetSymbol(lSymbol);

            var lBars = mBars[lSymbol];
            var lCurrentBar = lBars.Last(1);
            
            //Print("Hello...");
            DeletePendingOrderLong(lSymbol);
            DeletePendingOrderShort(lSymbol);

            if (lCurrentBar.Close < lCurrentBar.Open)
            {
                PlaceLimitOrder(TradeType.Sell, lSymbol, VolumeInUnits(mInitVolume, lCurrentSymbol), Math.Round(lCurrentBar.Open, lCurrentSymbol.Digits), mLabel + "_" + mPos++, null, null, null, mLabel);
            }

            if (lCurrentBar.Close > lCurrentBar.Open)
            {
                PlaceLimitOrder(TradeType.Buy, lSymbol, VolumeInUnits(mInitVolume, lCurrentSymbol), Math.Round(lCurrentBar.Close, lCurrentSymbol.Digits), mLabel + "_" + mPos++, null, null, null, mLabel);
            }
        }

        private double VolumeInUnits(int aFactor, Symbol aSymbol)
        {
            return aSymbol.QuantityToVolumeInUnits(aFactor * Quantity);
        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

 


@8034130
Replies

Dorfmeister72
01 Aug 2022, 02:46

Backtesting Performance issue

Hello,

Kind of same issue.

Just updated Ctrader to 4.2.15. Since then, I cannot run any backtesting on long period (ie more than 1 year) using "tick data from server"... Data Loading speed is just incredibly slow.

I have tried with 3 different brokers and same issue....

Thanks for your help


@Dorfmeister72

douglascvas
02 Aug 2022, 11:02 ( Updated at: 02 Aug 2022, 13:24 )

Same issue here. cTrader automate was slow before and now is way worse.

I have a Java platform which I created for myself, then I created a simple bot which uses multiple currencies. I translated the bot to c# as a cTrader robot to compare and check results.

Running a backtest on tick based data from January 2016 till now, my platform takes about 12 minutes to run while cTrader is currently taking around 2 days on the same bot (not counting the time to download the data).


@douglascvas

8034130
09 Aug 2022, 14:16

RE:

douglascvas said:

Same issue here. cTrader automate was slow before and now is way worse.

I have a Java platform which I created for myself, then I created a simple bot which uses multiple currencies. I translated the bot to c# as a cTrader robot to compare and check results.

Running a backtest on tick based data from January 2016 till now, my platform takes about 12 minutes to run while cTrader is currently taking around 2 days on the same bot (not counting the time to download the data).

Hello,

Is it possible to get a feedback ?

Best regards


@8034130

PanagiotisCharalampous
10 Aug 2022, 08:18

Hi all,

The team is working on a solution.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous