3.7 LoadMoreHistory() does nothing

Created at 09 Feb 2020, 18:06
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!
PU

PureForm

Joined 10.06.2019

3.7 LoadMoreHistory() does nothing
09 Feb 2020, 18:06


Hi,

I use an indicator which needs many bars of the past. This is no problem in live trading, because around 3000 historical bars get loaded here without scrolling. However in backtesting only 100 historical bars get loaded. That's not enough and I was very happy, when I read this will be addressed in 3.7.

Sadly, your example code does not work for me. I tried several pairs and timeframes, but the historical bars stay the same in backtesting. What am I missing? Here is a complete cBot code.

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 loadMOARbars : Robot
    {
        [Parameter(DefaultValue = 10000)]
        public int minbarcount { get; set; }
        
        Bars Bars2;
        int loadedCount;

        protected override void OnStart()
        {
            Bars2 = MarketData.GetBars(TimeFrame.Hour,"EURUSD");
            LoadMinBars(minbarcount);
        }

        protected override void OnBar()
        {
            Print ("Last Bar - Open: {0} \t Close: {1}", Bars2.Last(1).Open, Bars2.Last(1).Close);
        }
        
        private void LoadMinBars(int minbars)
        {
            int needbars = minbars - Bars2.Count;
            if (needbars > 0)
            {
                Print("{0} bars on the chart. Require {1} bars. Loading {2} more bars.", Bars2.Count, minbars, needbars);
                while (Bars2.Count < minbars)
                {
                    loadedCount = Bars2.LoadMoreHistory();
                    Print("Loaded {0} bars.", loadedCount);
                    if (loadedCount == 0)
                    {
                        Print("--- Error: Can't load more bars. Require {0} more. ---", minbars - Bars2.Count);
                        break;
                    }
                }
                Print("Finished loading more bars. Started with {0} bars. {1} bars available now.", minbars - needbars, Bars2.Count);
            }
        }
    }
}

 


@PureForm
Replies

PureForm
09 Feb 2020, 18:16

Here is my Log Dump:
 

08/01/2020 01:00:00.189 | Backtesting started
08/01/2020 01:00:00.189 | 99 bars on the chart. Require 10000 bars. Loading 9901 more bars.
08/01/2020 01:00:00.189 | Loaded 0 bars.
08/01/2020 01:00:00.189 | --- Error: Can't load more bars. Require 9901 more. ---
08/01/2020 01:00:00.189 | Finished loading more bars. Started with 99 bars. 99 bars available now.
08/01/2020 02:00:00.382 | Last Bar - Open: 1,1154 	 Close: 1,11587

 


@PureForm

PanagiotisCharalampous
10 Feb 2020, 12:19

Hi PureForm,

This is by design. Since in backtesting you can choose from where to start you can load as many bars as you want. If your indicator needs more bars, just start the backtesting from an earlier date so that the bars are loaded.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PureForm
10 Feb 2020, 14:58

Hi Panagiotis,

thanks for your quick reply. I can confirm my posted code works in live trading.

Still I'm a bit sad, this new feature does not work in backtesting. Now I have to stick with the workaround of two start dates for backtesting, one set in the backtesting GUI, the other one calculated inside the code or as parameter whereas I don't actually need that part of code for live trading. It's a bit inconvenient because depending on the timeframe 1000 bars can be 2 days of data or 20 days and I have to keep that in mind, when clicking on the start date in backtesting.

Maybe you can enable this feature for backtesting in a future release. A hard setting for number of historical backtesting bars in preferences or .ini file would also suffice.


@PureForm

mauriziolobello
23 Feb 2020, 17:13

RE:

PanagiotisCharalampous said:

Hi PureForm,

This is by design. Since in backtesting you can choose from where to start you can load as many bars as you want. If your indicator needs more bars, just start the backtesting from an earlier date so that the bars are loaded.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis, yes we can start backtesting from an earlier date and the bars are loaded. Just for example, let's suppose I need an EMA 300 periods for a TF of 4H, so I have to go back 50 days (2 months more or less) of backtesting to have some meaningful data, and I have to wait 300 periods to have my code checked. Frankly, it's a huge waste of time... really, huge!

I understand that the process of loading so much data from your servers is an optimization problem, I'm writing this note waiting for the backtesting to get to the point (I have "View Mode" on), and just a month has passed by at full speed (100000x, sic...), debugging this way becomes really too long of a process (yes, I have some log, indeed). So I hope you find another solution, one that allows us to get the data we want, and at the same time won't slow down your servers to their knees...

Thanks for your attention

Best Regards

Maurizio

 


@mauriziolobello

genappsforex
13 Apr 2020, 10:18

RE:

PanagiotisCharalampous said:

Hi PureForm,

This is by design. Since in backtesting you can choose from where to start you can load as many bars as you want. If your indicator needs more bars, just start the backtesting from an earlier date so that the bars are loaded.

Best Regards,

Panagiotis 

Join us on Telegram

 

Why is this by Design, What is the issue here?

Is it server load than the argument  is voided.
As people will have to start their backtest earlier still the same amount of data will be loaded from the server, so no wins there for Spotware or the brokers.

If there is an other issue please explain. Because I know all developers and traders agree on the fact that Backtesting should simulate live as much as possible.
So making weird constructs with two dates in backtesting is not a real option.

Please take this up with the development guys. IMHO it should be changed ASAP.

 


@genappsforex

protraderde
25 Apr 2024, 09:01 ( Updated at: 26 Apr 2024, 05:55 )

RE: RE:

genappsforex said: 

PanagiotisCharalampous said:

Hi PureForm,

This is by design. Since in backtesting you can choose from where to start you can load as many bars as you want. If your indicator needs more bars, just start the backtesting from an earlier date so that the bars are loaded.

Best Regards,

Panagiotis 

Join us on Telegram

 

Why is this by Design, What is the issue here?

Is it server load than the argument  is voided.
As people will have to start their backtest earlier still the same amount of data will be loaded from the server, so no wins there for Spotware or the brokers.

If there is an other issue please explain. Because I know all developers and traders agree on the fact that Backtesting should simulate live as much as possible.
So making weird constructs with two dates in backtesting is not a real option.

Please take this up with the development guys. IMHO it should be changed ASAP.

 

+1


@protraderde