Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access historical data in OnStartUp

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

    Access historical data in OnStartUp

    For implementing an indicator on historical data I have to access the full Input/Close data series several time. Now, it looks like that I don't have access to the data.
    The OnStartUp code:
    Code:
    Print("Inputs:"+Close.Count);
    for( int i = 0; i < Close.Count; i++ )
        Print("I:"+ i + ",V:" + Close[i]);
    leads to the following output:
    Inputs:1138
    I:0,V:1.3091
    I:1,V:1.3095
    I:2,V:1.3095
    I:3,V:1.3095
    I:4,V:1.3095
    I:5,V:1.3095
    I:6,V:1.3095
    Error on calling 'OnStartUp' method for indicator 'xxx': Object reference not set to an instance of an object.

    Any idea why this happens? The plot of the historical data works fine, so why I can't access the OHLC data?
    Thanks

    #2
    Hello,

    OnStartUp() only runs on the first bar (currentbar=0) on the chart.

    If you'd like to iterate through each bar on the chart, please work inside OnBarUpdate()
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks for your answer.
      The same code in OnBarUpdate:

      Inputs:1138
      I:0,V:1.3091
      I:1,V:1.3095
      I:2,V:1.3095
      I:3,V:1.3095
      I:4,V:1.3095
      I:5,V:1.3095
      I:6,V:1.3095
      Error on calling 'OnBarUpdate' method for indicator 'xxx': Object reference not set to an instance of an object.

      Ok, even if it supposed to work in OnBarUpdate why it doesn't work in OnStartUp? I'm trying to access the basic OHCL data which is available on OnStartUp - so why NT does not provide access to it? - any other trading system, like MT4/5, Wealth-Lab are allowing the access at any time!

      Let me short explain what I try to achieve: as I said it is a indicator on historical data. The historical data (1138 bars) are loaded and I can see a nice chart. Now, I try to run an indicator on it. The indicator needs to cycle through the OHLC data several times, means I need access to all the data. I don't want do access Close[0] in OnBarUpdate.
      Knowing this, what is NT's recommendation for doing this? Looks like Close[0] just gives you access to the current bar and the historical ones. Is there any other hidden data series which holds the real OHLC data?
      Last edited by TraderFrank; 08-28-2012, 07:25 AM.

      Comment


        #4
        Hello TradeFrank,
        You are trying to access the data before the bars had been built.

        Can you get the right Prints in OnBarUpdate event if you try the below code:
        Code:
        if (CurrentBar == Close.Count - 1)
        {
            for( int i = 0; i < Close.Count; i++ )
            Print("I:"+ i + ",V:" + Close[i]);
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Joydeep, thanks for your answer.
          I will try it later today, my assumption is that it will work. Basically you are saying that I have access to the full OHLC if the last OnBarUpdate passes the last bar data.

          Let me short explain what I try to achieve: as I said it is a indicator on historical data. The historical data (1138 bars) are loaded and I can see a nice chart. Now, I try to run an indicator on it. The indicator needs to cycle through the OHLC data several times, means I need access to all the data. I don't want do access Close[0] in OnBarUpdate. Looks like Close[0] just gives you access to the current bar and the historical ones.

          Is there any other hidden data series which holds the real OHLC data? My feeling is that for any reason NT is limiting the access to the raw data. If yes, why? And if yes, is there any other hidden data series which gives you full access to the raw data? The data is there somewhere hidden in NT. Basically I would like to cycle through the raw data already on OnStartUp.

          Comment


            #6
            Hello TradeFrank,
            You can use the below code to loop through the historical bar

            Code:
            protected override void OnBarUpdate()
            {
            
            	for (int i = 0; i <= CurrentBar; i++)
            	{
            		Print("I:"+ i + ",V:" + Close[i]);
            	}
            }
            http://www.ninjatrader.com/support/h...currentbar.htm

            Please note since the code loops on each bar, it is not an efficient way to calculate any variable.

            There may be other efficient ways depending on what exactly you are trying to calculate.

            Unfortunately there are no supported way to access the "hidden" data series.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Got it.
              Is there any reason why NT does not allow to access the raw data? As I said below, any other trading tools allows it. So in my opinion it's a restriction/missing feature which disqualifies NT somehow for professional use.

              Comment


                #8
                Hello TradeFrank,
                The other platforms exposes the bars once the whole bar has been built. NinjaTrader exposes the bar as it gets built. This makes NinjaTrader more versatile.

                You may like to refer to this thread to have a more understanding on how bars are to be accessed
                http://ninjatrader.com/support/forum...ead.php?t=3170
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by varun12343, Today, 03:09 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Marco  
                Started by Lance El Camino, Yesterday, 04:14 PM
                2 responses
                25 views
                0 likes
                Last Post NT-Roland  
                Started by MatthewLesko, Yesterday, 11:13 PM
                1 response
                14 views
                0 likes
                Last Post NT-Roland  
                Started by kevinenergy, Today, 01:44 AM
                0 responses
                8 views
                0 likes
                Last Post kevinenergy  
                Started by jtrading82, Yesterday, 04:56 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_ShawnB  
                Working...
                X