Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Harry, 05-02-2018, 01:54 PM
            10 responses
            3,203 views
            0 likes
            Last Post tharton3  
            Started by cre8able, Yesterday, 01:16 PM
            3 responses
            11 views
            0 likes
            Last Post cre8able  
            Started by ChartTourist, Today, 08:22 AM
            0 responses
            6 views
            0 likes
            Last Post ChartTourist  
            Started by LiamTwine, Today, 08:10 AM
            0 responses
            2 views
            0 likes
            Last Post LiamTwine  
            Started by Balage0922, Today, 07:38 AM
            0 responses
            5 views
            0 likes
            Last Post Balage0922  
            Working...
            X