Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieve all historical data in Backtesting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Retrieve all historical data in Backtesting

    Hi,

    I would like to know how can i retrieve all historical data in backtesting, such as Time[i] and Close[i], for example.
    I'm backtesting my strategy on a 1-day time frame from 2019/01/01 to today.

    When the backtest starts, on 2019/01/02 I just get the Time[0] and Close[0].
    The next day (2019/01/03) I get Time[0],Time[1] and Close[0], Close[1].
    The next day (2019/01/04) I get Time[0],Time[1],Time[2] and Close[0], Close[1], Close[2] and so on.

    How can I retrieve all historical Time and Close bars in the first day of backtesting?

    For example, i want to retrieve 100 days before the current day. How can i do that ?


    Thanks!
    Last edited by brunoviveiros; 07-24-2020, 07:41 AM.

    #2
    Hello brunoviveiros,

    Thank you for your reply.

    When you run a backtest, the strategy analyzer loads data for only the dates specified. So if you're testing from 1/1/19, it's not going to load historical data from before that. What you'd need to do if you wanted to retrieve data from the 100 historical bars before that is to increase the number of days you're loading by 100, then have a CurrentBar check so the strategy does not process until the 101st bar. That way you could then iterate back through those bars and get that historical data on the intended "first day" you want to test.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hello Kate,

      If I run my strategy in Realtime, will this problem occur or will the Time and Close retrieve all historical data?

      Comment


        #4
        Hello brunoviveiros,

        Thank you for your reply.

        Pretty much the same would apply to running the strategy on real time - you'd need to ensure you have 100 bars loaded of historical data and do a CurrentBars check, but then yes, you'd be able to iterate through the historical bars up to the current time to get that data to start processing.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          So, If I add my strategy with "Days to load" equal to 100, i will retrieve all historical data from 100 days ago in the Time and Close bars, correct?

          Comment


            #6
            Hello brunoviveiros,

            Thank you for your reply.

            Pretty much, you'd want to add a current bars check as well as I mentioned before.

            So you could do something like this:

            Code:
                    protected override void OnBarUpdate()
                    {
                        if(CurrentBar < 100)
                            return;
            
                        for (i= 0; i < 100; i++)
                        {
                            Print(Time[i] + " " Close[i]);
                        }
                    }
            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            72 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X